You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by pc...@apache.org on 2004/06/24 23:39:30 UTC
cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile Java2Schema.java TypeMatcher.java
pcal 2004/06/24 14:39:30
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/compile
Java2Schema.java TypeMatcher.java
Log:
b2b: relax object factory constraint j2s: set element form qualified
Revision Changes Path
1.54 +41 -17 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java
Index: Java2Schema.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- Java2Schema.java 24 Jun 2004 05:30:00 -0000 1.53
+++ Java2Schema.java 24 Jun 2004 21:39:30 -0000 1.54
@@ -34,6 +34,8 @@
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
+import java.util.Comparator;
+import java.util.Arrays;
import java.io.IOException;
import java.io.StringWriter;
@@ -96,6 +98,8 @@
// Set of JClasses for which element annotations have already been processed.
private Set mCheckForElements = new HashSet();
+ private boolean mOrderPropertiesBySource = false;
+
// =========================================================================
// Constructors
@@ -107,6 +111,21 @@
}
// ========================================================================
+ // Public methods
+
+ /**
+ * <p>Sets whether elements within generated schema types should be ordered
+ * according to the source order of their corresponding java properties.
+ * The default is false, meaning that they will instead be ordered
+ * alphabetically.</p>
+ *
+ * @param b
+ */
+ public void setOrderPropertiesBySource(boolean b) {
+ mOrderPropertiesBySource = b;
+ }
+
+ // ========================================================================
// BindingCompiler implementation
/**
@@ -170,7 +189,9 @@
SchemaDocument doc = (SchemaDocument)mTns2Schemadoc.get(tns);
if (doc == null) {
doc = SchemaDocument.Factory.newInstance();
- doc.addNewSchema().setTargetNamespace(tns);
+ SchemaDocument.Schema xsd = doc.addNewSchema();
+ xsd.setTargetNamespace(tns);
+ xsd.setElementFormDefault(FormChoice.QUALIFIED);
mTns2Schemadoc.put(tns,doc);
}
return doc.getSchema();
@@ -227,7 +248,7 @@
XmlTypeName.forGlobalName(XmlTypeName.ELEMENT, tes[i]));
SimpleDocumentBinding sdb = new SimpleDocumentBinding(docBtName);
sdb.setTypeOfElement(XmlTypeName.forTypeNamed(typeQName));
- mBindingFile.addBindingType(sdb,false,true);
+ mBindingFile.addBindingType(sdb,true,true);
}
}
}
@@ -348,6 +369,7 @@
private void bindProperties(JProperty[] props,
Map props2issetters,
SchemaPropertyFacade facade) {
+ if (mOrderPropertiesBySource) placeInSourceOrder(props);
for(int i=0; i<props.length; i++) {
if (mAnnHelper.getAnnotation(props[i],TAG_EL_EXCLUDE,false)) {
logVerbose("Marked excluded, skipping",props[i]);
@@ -702,21 +724,23 @@
}
}
+ private static Comparator SOURCE_POSITION_COMPARATOR = new Comparator() {
- //this is temporary, will go away when we have our 175 story straight
- private static JAnnotation[] getNamedTags(JAnnotation[] tags,
- String named)
- {
- if (tags == null || tags.length == 0) return new JAnnotation[0];
- List list = new ArrayList();
- for(int i=0; i<tags.length; i++) {
- if (tags[i].getSimpleName().equals(named)) list.add(tags[i]);
+ public int compare(Object o, Object o1) {
+ JSourcePosition p1 = ((JElement)o).getSourcePosition();
+ JSourcePosition p2 = ((JElement)o).getSourcePosition();
+ if (p1 == null) return (p2 == null) ? 0 : -1;
+ if (p2 == null) return 1;
+ return (p1.getLine() < p2.getLine()) ? -1 :
+ (p1.getLine() > p2.getLine()) ? 1 : 0;
}
- JAnnotation[] out = new JAnnotation[list.size()];
- list.toArray(out);
- return out;
- }
-
+ };
-
-}
+ /**
+ * Sorts the given array in place so that the elements are ordered by
+ * their sourcePosition line numbers.
+ */
+ private static void placeInSourceOrder(JElement[] elements) {
+ Arrays.sort(elements,SOURCE_POSITION_COMPARATOR);
+ }
+}
\ No newline at end of file
1.10 +5 -2 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcher.java
Index: TypeMatcher.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/TypeMatcher.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TypeMatcher.java 19 Jun 2004 00:31:46 -0000 1.9
+++ TypeMatcher.java 24 Jun 2004 21:39:30 -0000 1.10
@@ -123,7 +123,10 @@
JMethod factoryMethod)
{
this(jProperty,sProperty,isSetter);
- validateFactoryMethod(factoryMethod, jProperty);
+ // Skipping this for now so that people can write a single factory
+ // method which returns java.lang.Object. I'm a bit dubious about
+ // that. Maybe we should put a flag on this validation.
+ //validateFactoryMethod(factoryMethod, jProperty);
this.factoryMethod = factoryMethod;
}
@@ -188,7 +191,7 @@
if (!prop.getType().isAssignableFrom(factory.getReturnType())) {
throw new IllegalArgumentException
(factory.getQualifiedName()+
- " must return an "+prop.getType().getQualifiedName());
+ " must return an instance of "+prop.getType().getQualifiedName());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org