534 * Does schema in this namespace uses swaRef? If so, we need to generate import
535 * statement.
536 */
537 private boolean useSwaRef;
538
539 /**
540 * Import for mime namespace needs to be generated.
541 * See #856
542 */
543 private boolean useMimeNs;
544
545 public Namespace(String uri) {
546 this.uri = uri;
547 assert !XmlSchemaGenerator.this.namespaces.containsKey(uri);
548 XmlSchemaGenerator.this.namespaces.put(uri,this);
549 }
550
551 /**
552 * Process the given PropertyInfo looking for references to namespaces that
553 * are foreign to the given namespace. Any foreign namespace references
554 * found are added to the given namespaces dependency list and an <import>
555 * is generated for it.
556 *
557 * @param p the PropertyInfo
558 */
559 private void processForeignNamespaces(PropertyInfo<T, C> p, int processingDepth) {
560 for (TypeInfo<T, C> t : p.ref()) {
561 if ((t instanceof ClassInfo) && (processingDepth > 0)) {
562 java.util.List<PropertyInfo> l = ((ClassInfo) t).getProperties();
563 for (PropertyInfo subp : l) {
564 processForeignNamespaces(subp, --processingDepth);
565 }
566 }
567 if (t instanceof Element) {
568 addDependencyTo(((Element) t).getElementName());
569 }
570 if (t instanceof NonElement) {
571 addDependencyTo(((NonElement) t).getTypeName());
572 }
573 }
574 }
1123 }
1124 e.name(ename.getLocalPart());
1125 elementFormDefault.writeForm(e,ename);
1126
1127 if(ep.isCollectionNillable()) {
1128 e.nillable(true);
1129 }
1130 writeOccurs(e,!ep.isCollectionRequired(),repeated);
1131
1132 ComplexType p = e.complexType();
1133 choice.write(p);
1134 }
1135 };
1136 } else {// non-wrapped
1137 return choice;
1138 }
1139 }
1140
1141 /**
1142 * Checks if we can collapse
1143 * <element name='foo' type='t' /> to <element ref='foo' />.
1144 *
1145 * This is possible if we already have such declaration to begin with.
1146 */
1147 private boolean canBeDirectElementRef(TypeRef<T, C> t, QName tn, TypeInfo parentInfo) {
1148 Element te = null;
1149 ClassInfo ci = null;
1150 QName targetTagName = null;
1151
1152 if(t.isNillable() || t.getDefaultValue()!=null) {
1153 // can't put those attributes on <element ref>
1154 return false;
1155 }
1156
1157 if (t.getTarget() instanceof Element) {
1158 te = (Element) t.getTarget();
1159 targetTagName = te.getElementName();
1160 if (te instanceof ClassInfo) {
1161 ci = (ClassInfo)te;
1162 }
1163 }
|
534 * Does schema in this namespace uses swaRef? If so, we need to generate import
535 * statement.
536 */
537 private boolean useSwaRef;
538
539 /**
540 * Import for mime namespace needs to be generated.
541 * See #856
542 */
543 private boolean useMimeNs;
544
545 public Namespace(String uri) {
546 this.uri = uri;
547 assert !XmlSchemaGenerator.this.namespaces.containsKey(uri);
548 XmlSchemaGenerator.this.namespaces.put(uri,this);
549 }
550
551 /**
552 * Process the given PropertyInfo looking for references to namespaces that
553 * are foreign to the given namespace. Any foreign namespace references
554 * found are added to the given namespaces dependency list and an {@code <import>}
555 * is generated for it.
556 *
557 * @param p the PropertyInfo
558 */
559 private void processForeignNamespaces(PropertyInfo<T, C> p, int processingDepth) {
560 for (TypeInfo<T, C> t : p.ref()) {
561 if ((t instanceof ClassInfo) && (processingDepth > 0)) {
562 java.util.List<PropertyInfo> l = ((ClassInfo) t).getProperties();
563 for (PropertyInfo subp : l) {
564 processForeignNamespaces(subp, --processingDepth);
565 }
566 }
567 if (t instanceof Element) {
568 addDependencyTo(((Element) t).getElementName());
569 }
570 if (t instanceof NonElement) {
571 addDependencyTo(((NonElement) t).getTypeName());
572 }
573 }
574 }
1123 }
1124 e.name(ename.getLocalPart());
1125 elementFormDefault.writeForm(e,ename);
1126
1127 if(ep.isCollectionNillable()) {
1128 e.nillable(true);
1129 }
1130 writeOccurs(e,!ep.isCollectionRequired(),repeated);
1131
1132 ComplexType p = e.complexType();
1133 choice.write(p);
1134 }
1135 };
1136 } else {// non-wrapped
1137 return choice;
1138 }
1139 }
1140
1141 /**
1142 * Checks if we can collapse
1143 * {@code <element name='foo' type='t' />}
1144 * to {@code <element ref='foo' />}.
1145 *
1146 * This is possible if we already have such declaration to begin with.
1147 */
1148 private boolean canBeDirectElementRef(TypeRef<T, C> t, QName tn, TypeInfo parentInfo) {
1149 Element te = null;
1150 ClassInfo ci = null;
1151 QName targetTagName = null;
1152
1153 if(t.isNillable() || t.getDefaultValue()!=null) {
1154 // can't put those attributes on <element ref>
1155 return false;
1156 }
1157
1158 if (t.getTarget() instanceof Element) {
1159 te = (Element) t.getTarget();
1160 targetTagName = te.getElementName();
1161 if (te instanceof ClassInfo) {
1162 ci = (ClassInfo)te;
1163 }
1164 }
|