juneau-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamesbog...@apache.org
Subject [03/34] incubator-juneau-website git commit: Update javadocs
Date Sun, 10 Sep 2017 20:32:15 GMT
http://git-wip-us.apache.org/repos/asf/incubator-juneau-website/blob/62afb533/content/site/apidocs/src-html/org/apache/juneau/xml/XmlSchemaSerializerSession.html
----------------------------------------------------------------------
diff --git a/content/site/apidocs/src-html/org/apache/juneau/xml/XmlSchemaSerializerSession.html b/content/site/apidocs/src-html/org/apache/juneau/xml/XmlSchemaSerializerSession.html
index 2ab742f..9a65496 100644
--- a/content/site/apidocs/src-html/org/apache/juneau/xml/XmlSchemaSerializerSession.html
+++ b/content/site/apidocs/src-html/org/apache/juneau/xml/XmlSchemaSerializerSession.html
@@ -70,7 +70,7 @@
 <span class="sourceLineNo">062</span>      Namespace xs = xsNamespace;<a name="line.62"></a>
 <span class="sourceLineNo">063</span>      Namespace[] allNs = append(new Namespace[]{defaultNamespace}, namespaces);<a name="line.63"></a>
 <span class="sourceLineNo">064</span><a name="line.64"></a>
-<span class="sourceLineNo">065</span>      Schemas schemas = new Schemas(xs, defaultNamespace, allNs);<a name="line.65"></a>
+<span class="sourceLineNo">065</span>      Schemas schemas = new Schemas(this, xs, defaultNamespace, allNs);<a name="line.65"></a>
 <span class="sourceLineNo">066</span>      schemas.process(o);<a name="line.66"></a>
 <span class="sourceLineNo">067</span>      schemas.serializeTo(out.getWriter());<a name="line.67"></a>
 <span class="sourceLineNo">068</span>   }<a name="line.68"></a>
@@ -152,410 +152,412 @@
 <span class="sourceLineNo">144</span>      private static final long serialVersionUID = 1L;<a name="line.144"></a>
 <span class="sourceLineNo">145</span><a name="line.145"></a>
 <span class="sourceLineNo">146</span>      private Namespace defaultNs;<a name="line.146"></a>
-<span class="sourceLineNo">147</span>      private LinkedList&lt;QueueEntry&gt;<a name="line.147"></a>
-<span class="sourceLineNo">148</span>         elementQueue = new LinkedList&lt;QueueEntry&gt;(),<a name="line.148"></a>
-<span class="sourceLineNo">149</span>         attributeQueue = new LinkedList&lt;QueueEntry&gt;(),<a name="line.149"></a>
-<span class="sourceLineNo">150</span>         typeQueue = new LinkedList&lt;QueueEntry&gt;();<a name="line.150"></a>
-<span class="sourceLineNo">151</span><a name="line.151"></a>
-<span class="sourceLineNo">152</span>      private Schemas(Namespace xs, Namespace defaultNs, Namespace[] allNs) throws IOException {<a name="line.152"></a>
-<span class="sourceLineNo">153</span>         this.defaultNs = defaultNs;<a name="line.153"></a>
-<span class="sourceLineNo">154</span>         for (Namespace ns : allNs)<a name="line.154"></a>
-<span class="sourceLineNo">155</span>            put(ns, new Schema(this, xs, ns, defaultNs, allNs));<a name="line.155"></a>
-<span class="sourceLineNo">156</span>      }<a name="line.156"></a>
-<span class="sourceLineNo">157</span><a name="line.157"></a>
-<span class="sourceLineNo">158</span>      private Schema getSchema(Namespace ns) {<a name="line.158"></a>
-<span class="sourceLineNo">159</span>         if (ns == null)<a name="line.159"></a>
-<span class="sourceLineNo">160</span>            ns = defaultNs;<a name="line.160"></a>
-<span class="sourceLineNo">161</span>         Schema s = get(ns);<a name="line.161"></a>
-<span class="sourceLineNo">162</span>         if (s == null)<a name="line.162"></a>
-<span class="sourceLineNo">163</span>            throw new FormattedRuntimeException("No schema defined for namespace ''{0}''", ns);<a name="line.163"></a>
-<span class="sourceLineNo">164</span>         return s;<a name="line.164"></a>
-<span class="sourceLineNo">165</span>      }<a name="line.165"></a>
-<span class="sourceLineNo">166</span><a name="line.166"></a>
-<span class="sourceLineNo">167</span>      private void process(Object o) throws IOException {<a name="line.167"></a>
-<span class="sourceLineNo">168</span>         ClassMeta&lt;?&gt; cm = getClassMetaForObject(o);<a name="line.168"></a>
-<span class="sourceLineNo">169</span>         Namespace ns = defaultNs;<a name="line.169"></a>
-<span class="sourceLineNo">170</span>         if (cm == null)<a name="line.170"></a>
-<span class="sourceLineNo">171</span>            queueElement(ns, "null", object());<a name="line.171"></a>
-<span class="sourceLineNo">172</span>         else {<a name="line.172"></a>
-<span class="sourceLineNo">173</span>            XmlClassMeta xmlMeta = cm.getExtendedMeta(XmlClassMeta.class);<a name="line.173"></a>
-<span class="sourceLineNo">174</span>            if (cm.getDictionaryName() != null &amp;&amp; xmlMeta.getNamespace() != null)<a name="line.174"></a>
-<span class="sourceLineNo">175</span>               ns = xmlMeta.getNamespace();<a name="line.175"></a>
-<span class="sourceLineNo">176</span>            queueElement(ns, cm.getDictionaryName(), cm);<a name="line.176"></a>
-<span class="sourceLineNo">177</span>         }<a name="line.177"></a>
-<span class="sourceLineNo">178</span>         processQueue();<a name="line.178"></a>
-<span class="sourceLineNo">179</span>      }<a name="line.179"></a>
-<span class="sourceLineNo">180</span><a name="line.180"></a>
-<span class="sourceLineNo">181</span><a name="line.181"></a>
-<span class="sourceLineNo">182</span>      private void processQueue() throws IOException {<a name="line.182"></a>
-<span class="sourceLineNo">183</span>         boolean b;<a name="line.183"></a>
-<span class="sourceLineNo">184</span>         do {<a name="line.184"></a>
-<span class="sourceLineNo">185</span>            b = false;<a name="line.185"></a>
-<span class="sourceLineNo">186</span>            while (! elementQueue.isEmpty()) {<a name="line.186"></a>
-<span class="sourceLineNo">187</span>               QueueEntry q = elementQueue.removeFirst();<a name="line.187"></a>
-<span class="sourceLineNo">188</span>               b |= getSchema(q.ns).processElement(q.name, q.cm);<a name="line.188"></a>
-<span class="sourceLineNo">189</span>            }<a name="line.189"></a>
-<span class="sourceLineNo">190</span>            while (! typeQueue.isEmpty()) {<a name="line.190"></a>
-<span class="sourceLineNo">191</span>               QueueEntry q = typeQueue.removeFirst();<a name="line.191"></a>
-<span class="sourceLineNo">192</span>               b |= getSchema(q.ns).processType(q.name, q.cm);<a name="line.192"></a>
-<span class="sourceLineNo">193</span>            }<a name="line.193"></a>
-<span class="sourceLineNo">194</span>            while (! attributeQueue.isEmpty()) {<a name="line.194"></a>
-<span class="sourceLineNo">195</span>               QueueEntry q = attributeQueue.removeFirst();<a name="line.195"></a>
-<span class="sourceLineNo">196</span>               b |= getSchema(q.ns).processAttribute(q.name, q.cm);<a name="line.196"></a>
-<span class="sourceLineNo">197</span>            }<a name="line.197"></a>
-<span class="sourceLineNo">198</span>         } while (b);<a name="line.198"></a>
-<span class="sourceLineNo">199</span>      }<a name="line.199"></a>
-<span class="sourceLineNo">200</span><a name="line.200"></a>
-<span class="sourceLineNo">201</span>      private void queueElement(Namespace ns, String name, ClassMeta&lt;?&gt; cm) {<a name="line.201"></a>
-<span class="sourceLineNo">202</span>         elementQueue.add(new QueueEntry(ns, name, cm));<a name="line.202"></a>
-<span class="sourceLineNo">203</span>      }<a name="line.203"></a>
-<span class="sourceLineNo">204</span><a name="line.204"></a>
-<span class="sourceLineNo">205</span>      private void queueType(Namespace ns, String name, ClassMeta&lt;?&gt; cm) {<a name="line.205"></a>
-<span class="sourceLineNo">206</span>         if (name == null)<a name="line.206"></a>
-<span class="sourceLineNo">207</span>            name = XmlUtils.encodeElementName(cm);<a name="line.207"></a>
-<span class="sourceLineNo">208</span>         typeQueue.add(new QueueEntry(ns, name, cm));<a name="line.208"></a>
-<span class="sourceLineNo">209</span>      }<a name="line.209"></a>
-<span class="sourceLineNo">210</span><a name="line.210"></a>
-<span class="sourceLineNo">211</span>      private void queueAttribute(Namespace ns, String name, ClassMeta&lt;?&gt; cm) {<a name="line.211"></a>
-<span class="sourceLineNo">212</span>         attributeQueue.add(new QueueEntry(ns, name, cm));<a name="line.212"></a>
-<span class="sourceLineNo">213</span>      }<a name="line.213"></a>
-<span class="sourceLineNo">214</span><a name="line.214"></a>
-<span class="sourceLineNo">215</span>      private void serializeTo(Writer w) throws IOException {<a name="line.215"></a>
-<span class="sourceLineNo">216</span>         boolean b = false;<a name="line.216"></a>
-<span class="sourceLineNo">217</span>         for (Schema s : values()) {<a name="line.217"></a>
-<span class="sourceLineNo">218</span>            if (b)<a name="line.218"></a>
-<span class="sourceLineNo">219</span>               w.append('\u0000');<a name="line.219"></a>
-<span class="sourceLineNo">220</span>            w.append(s.toString());<a name="line.220"></a>
-<span class="sourceLineNo">221</span>            b = true;<a name="line.221"></a>
-<span class="sourceLineNo">222</span>         }<a name="line.222"></a>
-<span class="sourceLineNo">223</span>      }<a name="line.223"></a>
-<span class="sourceLineNo">224</span>   }<a name="line.224"></a>
-<span class="sourceLineNo">225</span><a name="line.225"></a>
-<span class="sourceLineNo">226</span>   /* An encapsulation of a single schema. */<a name="line.226"></a>
-<span class="sourceLineNo">227</span>   private class Schema {<a name="line.227"></a>
-<span class="sourceLineNo">228</span>      private StringWriter sw = new StringWriter();<a name="line.228"></a>
-<span class="sourceLineNo">229</span>      private XmlWriter w;<a name="line.229"></a>
-<span class="sourceLineNo">230</span>      private Namespace defaultNs, targetNs;<a name="line.230"></a>
-<span class="sourceLineNo">231</span>      private Schemas schemas;<a name="line.231"></a>
-<span class="sourceLineNo">232</span>      private Set&lt;String&gt;<a name="line.232"></a>
-<span class="sourceLineNo">233</span>         processedTypes = new HashSet&lt;String&gt;(),<a name="line.233"></a>
-<span class="sourceLineNo">234</span>         processedAttributes = new HashSet&lt;String&gt;(),<a name="line.234"></a>
-<span class="sourceLineNo">235</span>         processedElements = new HashSet&lt;String&gt;();<a name="line.235"></a>
-<span class="sourceLineNo">236</span><a name="line.236"></a>
-<span class="sourceLineNo">237</span>      public Schema(Schemas schemas, Namespace xs, Namespace targetNs, Namespace defaultNs, Namespace[] allNs) throws IOException {<a name="line.237"></a>
-<span class="sourceLineNo">238</span>         this.schemas = schemas;<a name="line.238"></a>
-<span class="sourceLineNo">239</span>         this.defaultNs = defaultNs;<a name="line.239"></a>
-<span class="sourceLineNo">240</span>         this.targetNs = targetNs;<a name="line.240"></a>
-<span class="sourceLineNo">241</span>         w = new XmlWriter(sw, isUseWhitespace(), getMaxIndent(), isTrimStrings(), getQuoteChar(), null, true, null);<a name="line.241"></a>
-<span class="sourceLineNo">242</span>         int i = indent;<a name="line.242"></a>
-<span class="sourceLineNo">243</span>         w.oTag(i, "schema");<a name="line.243"></a>
-<span class="sourceLineNo">244</span>         w.attr("xmlns", xs.getUri());<a name="line.244"></a>
-<span class="sourceLineNo">245</span>         w.attr("targetNamespace", targetNs.getUri());<a name="line.245"></a>
-<span class="sourceLineNo">246</span>         w.attr("elementFormDefault", "qualified");<a name="line.246"></a>
-<span class="sourceLineNo">247</span>         if (targetNs != defaultNs)<a name="line.247"></a>
-<span class="sourceLineNo">248</span>            w.attr("attributeFormDefault", "qualified");<a name="line.248"></a>
-<span class="sourceLineNo">249</span>         for (Namespace ns2 : allNs)<a name="line.249"></a>
-<span class="sourceLineNo">250</span>            w.attr("xmlns", ns2.name, ns2.uri);<a name="line.250"></a>
-<span class="sourceLineNo">251</span>         w.append('&gt;').nl(i);<a name="line.251"></a>
-<span class="sourceLineNo">252</span>         for (Namespace ns : allNs) {<a name="line.252"></a>
-<span class="sourceLineNo">253</span>            if (ns != targetNs) {<a name="line.253"></a>
-<span class="sourceLineNo">254</span>               w.oTag(i+1, "import")<a name="line.254"></a>
-<span class="sourceLineNo">255</span>                  .attr("namespace", ns.getUri())<a name="line.255"></a>
-<span class="sourceLineNo">256</span>                  .attr("schemaLocation", ns.getName()+".xsd")<a name="line.256"></a>
-<span class="sourceLineNo">257</span>                  .append("/&gt;").nl(i+1);<a name="line.257"></a>
-<span class="sourceLineNo">258</span>            }<a name="line.258"></a>
-<span class="sourceLineNo">259</span>         }<a name="line.259"></a>
-<span class="sourceLineNo">260</span>      }<a name="line.260"></a>
-<span class="sourceLineNo">261</span><a name="line.261"></a>
-<span class="sourceLineNo">262</span>      private boolean processElement(String name, ClassMeta&lt;?&gt; cm) throws IOException {<a name="line.262"></a>
-<span class="sourceLineNo">263</span>         if (processedElements.contains(name))<a name="line.263"></a>
-<span class="sourceLineNo">264</span>            return false;<a name="line.264"></a>
-<span class="sourceLineNo">265</span>         processedElements.add(name);<a name="line.265"></a>
-<span class="sourceLineNo">266</span><a name="line.266"></a>
-<span class="sourceLineNo">267</span>         ClassMeta&lt;?&gt; ft = cm.getSerializedClassMeta();<a name="line.267"></a>
-<span class="sourceLineNo">268</span>         if (name == null)<a name="line.268"></a>
-<span class="sourceLineNo">269</span>            name = getElementName(ft);<a name="line.269"></a>
-<span class="sourceLineNo">270</span>         Namespace ns = first(ft.getExtendedMeta(XmlClassMeta.class).getNamespace(), defaultNs);<a name="line.270"></a>
-<span class="sourceLineNo">271</span>         String type = getXmlType(ns, ft);<a name="line.271"></a>
-<span class="sourceLineNo">272</span><a name="line.272"></a>
-<span class="sourceLineNo">273</span>         w.oTag(indent+1, "element")<a name="line.273"></a>
-<span class="sourceLineNo">274</span>            .attr("name", XmlUtils.encodeElementName(name))<a name="line.274"></a>
-<span class="sourceLineNo">275</span>            .attr("type", type)<a name="line.275"></a>
-<span class="sourceLineNo">276</span>            .append('/').append('&gt;').nl(indent+1);<a name="line.276"></a>
-<span class="sourceLineNo">277</span><a name="line.277"></a>
-<span class="sourceLineNo">278</span>         schemas.queueType(ns, null, ft);<a name="line.278"></a>
-<span class="sourceLineNo">279</span>         schemas.processQueue();<a name="line.279"></a>
-<span class="sourceLineNo">280</span>         return true;<a name="line.280"></a>
-<span class="sourceLineNo">281</span>      }<a name="line.281"></a>
-<span class="sourceLineNo">282</span><a name="line.282"></a>
-<span class="sourceLineNo">283</span>      private boolean processAttribute(String name, ClassMeta&lt;?&gt; cm) throws IOException {<a name="line.283"></a>
-<span class="sourceLineNo">284</span>         if (processedAttributes.contains(name))<a name="line.284"></a>
-<span class="sourceLineNo">285</span>            return false;<a name="line.285"></a>
-<span class="sourceLineNo">286</span>         processedAttributes.add(name);<a name="line.286"></a>
-<span class="sourceLineNo">287</span><a name="line.287"></a>
-<span class="sourceLineNo">288</span>         String type = getXmlAttrType(cm);<a name="line.288"></a>
+<span class="sourceLineNo">147</span>      private BeanSession session;<a name="line.147"></a>
+<span class="sourceLineNo">148</span>      private LinkedList&lt;QueueEntry&gt;<a name="line.148"></a>
+<span class="sourceLineNo">149</span>         elementQueue = new LinkedList&lt;QueueEntry&gt;(),<a name="line.149"></a>
+<span class="sourceLineNo">150</span>         attributeQueue = new LinkedList&lt;QueueEntry&gt;(),<a name="line.150"></a>
+<span class="sourceLineNo">151</span>         typeQueue = new LinkedList&lt;QueueEntry&gt;();<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>      private Schemas(BeanSession session, Namespace xs, Namespace defaultNs, Namespace[] allNs) throws IOException {<a name="line.153"></a>
+<span class="sourceLineNo">154</span>         this.session = session;<a name="line.154"></a>
+<span class="sourceLineNo">155</span>         this.defaultNs = defaultNs;<a name="line.155"></a>
+<span class="sourceLineNo">156</span>         for (Namespace ns : allNs)<a name="line.156"></a>
+<span class="sourceLineNo">157</span>            put(ns, new Schema(this, xs, ns, defaultNs, allNs));<a name="line.157"></a>
+<span class="sourceLineNo">158</span>      }<a name="line.158"></a>
+<span class="sourceLineNo">159</span><a name="line.159"></a>
+<span class="sourceLineNo">160</span>      private Schema getSchema(Namespace ns) {<a name="line.160"></a>
+<span class="sourceLineNo">161</span>         if (ns == null)<a name="line.161"></a>
+<span class="sourceLineNo">162</span>            ns = defaultNs;<a name="line.162"></a>
+<span class="sourceLineNo">163</span>         Schema s = get(ns);<a name="line.163"></a>
+<span class="sourceLineNo">164</span>         if (s == null)<a name="line.164"></a>
+<span class="sourceLineNo">165</span>            throw new FormattedRuntimeException("No schema defined for namespace ''{0}''", ns);<a name="line.165"></a>
+<span class="sourceLineNo">166</span>         return s;<a name="line.166"></a>
+<span class="sourceLineNo">167</span>      }<a name="line.167"></a>
+<span class="sourceLineNo">168</span><a name="line.168"></a>
+<span class="sourceLineNo">169</span>      private void process(Object o) throws IOException {<a name="line.169"></a>
+<span class="sourceLineNo">170</span>         ClassMeta&lt;?&gt; cm = getClassMetaForObject(o);<a name="line.170"></a>
+<span class="sourceLineNo">171</span>         Namespace ns = defaultNs;<a name="line.171"></a>
+<span class="sourceLineNo">172</span>         if (cm == null)<a name="line.172"></a>
+<span class="sourceLineNo">173</span>            queueElement(ns, "null", object());<a name="line.173"></a>
+<span class="sourceLineNo">174</span>         else {<a name="line.174"></a>
+<span class="sourceLineNo">175</span>            XmlClassMeta xmlMeta = cm.getExtendedMeta(XmlClassMeta.class);<a name="line.175"></a>
+<span class="sourceLineNo">176</span>            if (cm.getDictionaryName() != null &amp;&amp; xmlMeta.getNamespace() != null)<a name="line.176"></a>
+<span class="sourceLineNo">177</span>               ns = xmlMeta.getNamespace();<a name="line.177"></a>
+<span class="sourceLineNo">178</span>            queueElement(ns, cm.getDictionaryName(), cm);<a name="line.178"></a>
+<span class="sourceLineNo">179</span>         }<a name="line.179"></a>
+<span class="sourceLineNo">180</span>         processQueue();<a name="line.180"></a>
+<span class="sourceLineNo">181</span>      }<a name="line.181"></a>
+<span class="sourceLineNo">182</span><a name="line.182"></a>
+<span class="sourceLineNo">183</span><a name="line.183"></a>
+<span class="sourceLineNo">184</span>      private void processQueue() throws IOException {<a name="line.184"></a>
+<span class="sourceLineNo">185</span>         boolean b;<a name="line.185"></a>
+<span class="sourceLineNo">186</span>         do {<a name="line.186"></a>
+<span class="sourceLineNo">187</span>            b = false;<a name="line.187"></a>
+<span class="sourceLineNo">188</span>            while (! elementQueue.isEmpty()) {<a name="line.188"></a>
+<span class="sourceLineNo">189</span>               QueueEntry q = elementQueue.removeFirst();<a name="line.189"></a>
+<span class="sourceLineNo">190</span>               b |= getSchema(q.ns).processElement(q.name, q.cm);<a name="line.190"></a>
+<span class="sourceLineNo">191</span>            }<a name="line.191"></a>
+<span class="sourceLineNo">192</span>            while (! typeQueue.isEmpty()) {<a name="line.192"></a>
+<span class="sourceLineNo">193</span>               QueueEntry q = typeQueue.removeFirst();<a name="line.193"></a>
+<span class="sourceLineNo">194</span>               b |= getSchema(q.ns).processType(q.name, q.cm);<a name="line.194"></a>
+<span class="sourceLineNo">195</span>            }<a name="line.195"></a>
+<span class="sourceLineNo">196</span>            while (! attributeQueue.isEmpty()) {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>               QueueEntry q = attributeQueue.removeFirst();<a name="line.197"></a>
+<span class="sourceLineNo">198</span>               b |= getSchema(q.ns).processAttribute(q.name, q.cm);<a name="line.198"></a>
+<span class="sourceLineNo">199</span>            }<a name="line.199"></a>
+<span class="sourceLineNo">200</span>         } while (b);<a name="line.200"></a>
+<span class="sourceLineNo">201</span>      }<a name="line.201"></a>
+<span class="sourceLineNo">202</span><a name="line.202"></a>
+<span class="sourceLineNo">203</span>      private void queueElement(Namespace ns, String name, ClassMeta&lt;?&gt; cm) {<a name="line.203"></a>
+<span class="sourceLineNo">204</span>         elementQueue.add(new QueueEntry(ns, name, cm));<a name="line.204"></a>
+<span class="sourceLineNo">205</span>      }<a name="line.205"></a>
+<span class="sourceLineNo">206</span><a name="line.206"></a>
+<span class="sourceLineNo">207</span>      private void queueType(Namespace ns, String name, ClassMeta&lt;?&gt; cm) {<a name="line.207"></a>
+<span class="sourceLineNo">208</span>         if (name == null)<a name="line.208"></a>
+<span class="sourceLineNo">209</span>            name = XmlUtils.encodeElementName(cm);<a name="line.209"></a>
+<span class="sourceLineNo">210</span>         typeQueue.add(new QueueEntry(ns, name, cm));<a name="line.210"></a>
+<span class="sourceLineNo">211</span>      }<a name="line.211"></a>
+<span class="sourceLineNo">212</span><a name="line.212"></a>
+<span class="sourceLineNo">213</span>      private void queueAttribute(Namespace ns, String name, ClassMeta&lt;?&gt; cm) {<a name="line.213"></a>
+<span class="sourceLineNo">214</span>         attributeQueue.add(new QueueEntry(ns, name, cm));<a name="line.214"></a>
+<span class="sourceLineNo">215</span>      }<a name="line.215"></a>
+<span class="sourceLineNo">216</span><a name="line.216"></a>
+<span class="sourceLineNo">217</span>      private void serializeTo(Writer w) throws IOException {<a name="line.217"></a>
+<span class="sourceLineNo">218</span>         boolean b = false;<a name="line.218"></a>
+<span class="sourceLineNo">219</span>         for (Schema s : values()) {<a name="line.219"></a>
+<span class="sourceLineNo">220</span>            if (b)<a name="line.220"></a>
+<span class="sourceLineNo">221</span>               w.append('\u0000');<a name="line.221"></a>
+<span class="sourceLineNo">222</span>            w.append(s.toString());<a name="line.222"></a>
+<span class="sourceLineNo">223</span>            b = true;<a name="line.223"></a>
+<span class="sourceLineNo">224</span>         }<a name="line.224"></a>
+<span class="sourceLineNo">225</span>      }<a name="line.225"></a>
+<span class="sourceLineNo">226</span>   }<a name="line.226"></a>
+<span class="sourceLineNo">227</span><a name="line.227"></a>
+<span class="sourceLineNo">228</span>   /* An encapsulation of a single schema. */<a name="line.228"></a>
+<span class="sourceLineNo">229</span>   private class Schema {<a name="line.229"></a>
+<span class="sourceLineNo">230</span>      private StringWriter sw = new StringWriter();<a name="line.230"></a>
+<span class="sourceLineNo">231</span>      private XmlWriter w;<a name="line.231"></a>
+<span class="sourceLineNo">232</span>      private Namespace defaultNs, targetNs;<a name="line.232"></a>
+<span class="sourceLineNo">233</span>      private Schemas schemas;<a name="line.233"></a>
+<span class="sourceLineNo">234</span>      private Set&lt;String&gt;<a name="line.234"></a>
+<span class="sourceLineNo">235</span>         processedTypes = new HashSet&lt;String&gt;(),<a name="line.235"></a>
+<span class="sourceLineNo">236</span>         processedAttributes = new HashSet&lt;String&gt;(),<a name="line.236"></a>
+<span class="sourceLineNo">237</span>         processedElements = new HashSet&lt;String&gt;();<a name="line.237"></a>
+<span class="sourceLineNo">238</span><a name="line.238"></a>
+<span class="sourceLineNo">239</span>      public Schema(Schemas schemas, Namespace xs, Namespace targetNs, Namespace defaultNs, Namespace[] allNs) throws IOException {<a name="line.239"></a>
+<span class="sourceLineNo">240</span>         this.schemas = schemas;<a name="line.240"></a>
+<span class="sourceLineNo">241</span>         this.defaultNs = defaultNs;<a name="line.241"></a>
+<span class="sourceLineNo">242</span>         this.targetNs = targetNs;<a name="line.242"></a>
+<span class="sourceLineNo">243</span>         w = new XmlWriter(sw, isUseWhitespace(), getMaxIndent(), isTrimStrings(), getQuoteChar(), null, true, null);<a name="line.243"></a>
+<span class="sourceLineNo">244</span>         int i = indent;<a name="line.244"></a>
+<span class="sourceLineNo">245</span>         w.oTag(i, "schema");<a name="line.245"></a>
+<span class="sourceLineNo">246</span>         w.attr("xmlns", xs.getUri());<a name="line.246"></a>
+<span class="sourceLineNo">247</span>         w.attr("targetNamespace", targetNs.getUri());<a name="line.247"></a>
+<span class="sourceLineNo">248</span>         w.attr("elementFormDefault", "qualified");<a name="line.248"></a>
+<span class="sourceLineNo">249</span>         if (targetNs != defaultNs)<a name="line.249"></a>
+<span class="sourceLineNo">250</span>            w.attr("attributeFormDefault", "qualified");<a name="line.250"></a>
+<span class="sourceLineNo">251</span>         for (Namespace ns2 : allNs)<a name="line.251"></a>
+<span class="sourceLineNo">252</span>            w.attr("xmlns", ns2.name, ns2.uri);<a name="line.252"></a>
+<span class="sourceLineNo">253</span>         w.append('&gt;').nl(i);<a name="line.253"></a>
+<span class="sourceLineNo">254</span>         for (Namespace ns : allNs) {<a name="line.254"></a>
+<span class="sourceLineNo">255</span>            if (ns != targetNs) {<a name="line.255"></a>
+<span class="sourceLineNo">256</span>               w.oTag(i+1, "import")<a name="line.256"></a>
+<span class="sourceLineNo">257</span>                  .attr("namespace", ns.getUri())<a name="line.257"></a>
+<span class="sourceLineNo">258</span>                  .attr("schemaLocation", ns.getName()+".xsd")<a name="line.258"></a>
+<span class="sourceLineNo">259</span>                  .append("/&gt;").nl(i+1);<a name="line.259"></a>
+<span class="sourceLineNo">260</span>            }<a name="line.260"></a>
+<span class="sourceLineNo">261</span>         }<a name="line.261"></a>
+<span class="sourceLineNo">262</span>      }<a name="line.262"></a>
+<span class="sourceLineNo">263</span><a name="line.263"></a>
+<span class="sourceLineNo">264</span>      private boolean processElement(String name, ClassMeta&lt;?&gt; cm) throws IOException {<a name="line.264"></a>
+<span class="sourceLineNo">265</span>         if (processedElements.contains(name))<a name="line.265"></a>
+<span class="sourceLineNo">266</span>            return false;<a name="line.266"></a>
+<span class="sourceLineNo">267</span>         processedElements.add(name);<a name="line.267"></a>
+<span class="sourceLineNo">268</span><a name="line.268"></a>
+<span class="sourceLineNo">269</span>         ClassMeta&lt;?&gt; ft = cm.getSerializedClassMeta(schemas.session);<a name="line.269"></a>
+<span class="sourceLineNo">270</span>         if (name == null)<a name="line.270"></a>
+<span class="sourceLineNo">271</span>            name = getElementName(ft);<a name="line.271"></a>
+<span class="sourceLineNo">272</span>         Namespace ns = first(ft.getExtendedMeta(XmlClassMeta.class).getNamespace(), defaultNs);<a name="line.272"></a>
+<span class="sourceLineNo">273</span>         String type = getXmlType(ns, ft);<a name="line.273"></a>
+<span class="sourceLineNo">274</span><a name="line.274"></a>
+<span class="sourceLineNo">275</span>         w.oTag(indent+1, "element")<a name="line.275"></a>
+<span class="sourceLineNo">276</span>            .attr("name", XmlUtils.encodeElementName(name))<a name="line.276"></a>
+<span class="sourceLineNo">277</span>            .attr("type", type)<a name="line.277"></a>
+<span class="sourceLineNo">278</span>            .append('/').append('&gt;').nl(indent+1);<a name="line.278"></a>
+<span class="sourceLineNo">279</span><a name="line.279"></a>
+<span class="sourceLineNo">280</span>         schemas.queueType(ns, null, ft);<a name="line.280"></a>
+<span class="sourceLineNo">281</span>         schemas.processQueue();<a name="line.281"></a>
+<span class="sourceLineNo">282</span>         return true;<a name="line.282"></a>
+<span class="sourceLineNo">283</span>      }<a name="line.283"></a>
+<span class="sourceLineNo">284</span><a name="line.284"></a>
+<span class="sourceLineNo">285</span>      private boolean processAttribute(String name, ClassMeta&lt;?&gt; cm) throws IOException {<a name="line.285"></a>
+<span class="sourceLineNo">286</span>         if (processedAttributes.contains(name))<a name="line.286"></a>
+<span class="sourceLineNo">287</span>            return false;<a name="line.287"></a>
+<span class="sourceLineNo">288</span>         processedAttributes.add(name);<a name="line.288"></a>
 <span class="sourceLineNo">289</span><a name="line.289"></a>
-<span class="sourceLineNo">290</span>         w.oTag(indent+1, "attribute")<a name="line.290"></a>
-<span class="sourceLineNo">291</span>            .attr("name", name)<a name="line.291"></a>
-<span class="sourceLineNo">292</span>            .attr("type", type)<a name="line.292"></a>
-<span class="sourceLineNo">293</span>            .append('/').append('&gt;').nl(indent+1);<a name="line.293"></a>
-<span class="sourceLineNo">294</span><a name="line.294"></a>
-<span class="sourceLineNo">295</span>         return true;<a name="line.295"></a>
-<span class="sourceLineNo">296</span>      }<a name="line.296"></a>
-<span class="sourceLineNo">297</span><a name="line.297"></a>
-<span class="sourceLineNo">298</span>      private boolean processType(String name, ClassMeta&lt;?&gt; cm) throws IOException {<a name="line.298"></a>
-<span class="sourceLineNo">299</span>         if (processedTypes.contains(name))<a name="line.299"></a>
-<span class="sourceLineNo">300</span>            return false;<a name="line.300"></a>
-<span class="sourceLineNo">301</span>         processedTypes.add(name);<a name="line.301"></a>
-<span class="sourceLineNo">302</span><a name="line.302"></a>
-<span class="sourceLineNo">303</span>         int i = indent + 1;<a name="line.303"></a>
+<span class="sourceLineNo">290</span>         String type = getXmlAttrType(cm);<a name="line.290"></a>
+<span class="sourceLineNo">291</span><a name="line.291"></a>
+<span class="sourceLineNo">292</span>         w.oTag(indent+1, "attribute")<a name="line.292"></a>
+<span class="sourceLineNo">293</span>            .attr("name", name)<a name="line.293"></a>
+<span class="sourceLineNo">294</span>            .attr("type", type)<a name="line.294"></a>
+<span class="sourceLineNo">295</span>            .append('/').append('&gt;').nl(indent+1);<a name="line.295"></a>
+<span class="sourceLineNo">296</span><a name="line.296"></a>
+<span class="sourceLineNo">297</span>         return true;<a name="line.297"></a>
+<span class="sourceLineNo">298</span>      }<a name="line.298"></a>
+<span class="sourceLineNo">299</span><a name="line.299"></a>
+<span class="sourceLineNo">300</span>      private boolean processType(String name, ClassMeta&lt;?&gt; cm) throws IOException {<a name="line.300"></a>
+<span class="sourceLineNo">301</span>         if (processedTypes.contains(name))<a name="line.301"></a>
+<span class="sourceLineNo">302</span>            return false;<a name="line.302"></a>
+<span class="sourceLineNo">303</span>         processedTypes.add(name);<a name="line.303"></a>
 <span class="sourceLineNo">304</span><a name="line.304"></a>
-<span class="sourceLineNo">305</span>         cm = cm.getSerializedClassMeta();<a name="line.305"></a>
-<span class="sourceLineNo">306</span>         XmlBeanMeta xbm = cm.isBean() ? cm.getBeanMeta().getExtendedMeta(XmlBeanMeta.class) : null;<a name="line.306"></a>
-<span class="sourceLineNo">307</span><a name="line.307"></a>
-<span class="sourceLineNo">308</span>         w.oTag(i, "complexType")<a name="line.308"></a>
-<span class="sourceLineNo">309</span>            .attr("name", name);<a name="line.309"></a>
-<span class="sourceLineNo">310</span><a name="line.310"></a>
-<span class="sourceLineNo">311</span>         // This element can have mixed content if:<a name="line.311"></a>
-<span class="sourceLineNo">312</span>         //    1) It's a generic Object (so it can theoretically be anything)<a name="line.312"></a>
-<span class="sourceLineNo">313</span>         //    2) The bean has a property defined with @XmlFormat.CONTENT.<a name="line.313"></a>
-<span class="sourceLineNo">314</span>         if ((xbm != null &amp;&amp; (xbm.getContentFormat() != null &amp;&amp; xbm.getContentFormat().isOneOf(TEXT,TEXT_PWS,MIXED,MIXED_PWS,XMLTEXT))) || ! cm.isMapOrBean())<a name="line.314"></a>
-<span class="sourceLineNo">315</span>            w.attr("mixed", "true");<a name="line.315"></a>
-<span class="sourceLineNo">316</span><a name="line.316"></a>
-<span class="sourceLineNo">317</span>         w.cTag().nl(i);<a name="line.317"></a>
+<span class="sourceLineNo">305</span>         int i = indent + 1;<a name="line.305"></a>
+<span class="sourceLineNo">306</span><a name="line.306"></a>
+<span class="sourceLineNo">307</span>         cm = cm.getSerializedClassMeta(schemas.session);<a name="line.307"></a>
+<span class="sourceLineNo">308</span>         XmlBeanMeta xbm = cm.isBean() ? cm.getBeanMeta().getExtendedMeta(XmlBeanMeta.class) : null;<a name="line.308"></a>
+<span class="sourceLineNo">309</span><a name="line.309"></a>
+<span class="sourceLineNo">310</span>         w.oTag(i, "complexType")<a name="line.310"></a>
+<span class="sourceLineNo">311</span>            .attr("name", name);<a name="line.311"></a>
+<span class="sourceLineNo">312</span><a name="line.312"></a>
+<span class="sourceLineNo">313</span>         // This element can have mixed content if:<a name="line.313"></a>
+<span class="sourceLineNo">314</span>         //    1) It's a generic Object (so it can theoretically be anything)<a name="line.314"></a>
+<span class="sourceLineNo">315</span>         //    2) The bean has a property defined with @XmlFormat.CONTENT.<a name="line.315"></a>
+<span class="sourceLineNo">316</span>         if ((xbm != null &amp;&amp; (xbm.getContentFormat() != null &amp;&amp; xbm.getContentFormat().isOneOf(TEXT,TEXT_PWS,MIXED,MIXED_PWS,XMLTEXT))) || ! cm.isMapOrBean())<a name="line.316"></a>
+<span class="sourceLineNo">317</span>            w.attr("mixed", "true");<a name="line.317"></a>
 <span class="sourceLineNo">318</span><a name="line.318"></a>
-<span class="sourceLineNo">319</span>         if (! (cm.isMapOrBean() || cm.isCollectionOrArray() || (cm.isAbstract() &amp;&amp; ! cm.isNumber()) || cm.isObject())) {<a name="line.319"></a>
-<span class="sourceLineNo">320</span>            w.oTag(i+1, "attribute").attr("name", getBeanTypePropertyName(cm)).attr("type", "string").ceTag().nl(i+1);<a name="line.320"></a>
-<span class="sourceLineNo">321</span><a name="line.321"></a>
-<span class="sourceLineNo">322</span>         } else {<a name="line.322"></a>
+<span class="sourceLineNo">319</span>         w.cTag().nl(i);<a name="line.319"></a>
+<span class="sourceLineNo">320</span><a name="line.320"></a>
+<span class="sourceLineNo">321</span>         if (! (cm.isMapOrBean() || cm.isCollectionOrArray() || (cm.isAbstract() &amp;&amp; ! cm.isNumber()) || cm.isObject())) {<a name="line.321"></a>
+<span class="sourceLineNo">322</span>            w.oTag(i+1, "attribute").attr("name", getBeanTypePropertyName(cm)).attr("type", "string").ceTag().nl(i+1);<a name="line.322"></a>
 <span class="sourceLineNo">323</span><a name="line.323"></a>
-<span class="sourceLineNo">324</span>            //----- Bean -----<a name="line.324"></a>
-<span class="sourceLineNo">325</span>            if (cm.isBean()) {<a name="line.325"></a>
-<span class="sourceLineNo">326</span>               BeanMeta&lt;?&gt; bm = cm.getBeanMeta();<a name="line.326"></a>
-<span class="sourceLineNo">327</span><a name="line.327"></a>
-<span class="sourceLineNo">328</span>               boolean hasChildElements = false;<a name="line.328"></a>
+<span class="sourceLineNo">324</span>         } else {<a name="line.324"></a>
+<span class="sourceLineNo">325</span><a name="line.325"></a>
+<span class="sourceLineNo">326</span>            //----- Bean -----<a name="line.326"></a>
+<span class="sourceLineNo">327</span>            if (cm.isBean()) {<a name="line.327"></a>
+<span class="sourceLineNo">328</span>               BeanMeta&lt;?&gt; bm = cm.getBeanMeta();<a name="line.328"></a>
 <span class="sourceLineNo">329</span><a name="line.329"></a>
-<span class="sourceLineNo">330</span>               for (BeanPropertyMeta pMeta : bm.getPropertyMetas()) {<a name="line.330"></a>
-<span class="sourceLineNo">331</span>                  XmlFormat pMetaFormat = pMeta.getExtendedMeta(XmlBeanPropertyMeta.class).getXmlFormat();<a name="line.331"></a>
-<span class="sourceLineNo">332</span>                  if (pMetaFormat != XmlFormat.ATTR)<a name="line.332"></a>
-<span class="sourceLineNo">333</span>                     hasChildElements = true;<a name="line.333"></a>
-<span class="sourceLineNo">334</span>               }<a name="line.334"></a>
-<span class="sourceLineNo">335</span><a name="line.335"></a>
-<span class="sourceLineNo">336</span>               XmlBeanMeta xbm2 = bm.getExtendedMeta(XmlBeanMeta.class);<a name="line.336"></a>
-<span class="sourceLineNo">337</span>               if (xbm2.getContentProperty() != null &amp;&amp; xbm2.getContentFormat() == ELEMENTS) {<a name="line.337"></a>
-<span class="sourceLineNo">338</span>                  w.sTag(i+1, "sequence").nl(i+1);<a name="line.338"></a>
-<span class="sourceLineNo">339</span>                  w.oTag(i+2, "any")<a name="line.339"></a>
-<span class="sourceLineNo">340</span>                     .attr("processContents", "skip")<a name="line.340"></a>
-<span class="sourceLineNo">341</span>                     .attr("minOccurs", 0)<a name="line.341"></a>
-<span class="sourceLineNo">342</span>                     .ceTag().nl(i+2);<a name="line.342"></a>
-<span class="sourceLineNo">343</span>                  w.eTag(i+1, "sequence").nl(i+1);<a name="line.343"></a>
-<span class="sourceLineNo">344</span><a name="line.344"></a>
-<span class="sourceLineNo">345</span>               } else if (hasChildElements) {<a name="line.345"></a>
+<span class="sourceLineNo">330</span>               boolean hasChildElements = false;<a name="line.330"></a>
+<span class="sourceLineNo">331</span><a name="line.331"></a>
+<span class="sourceLineNo">332</span>               for (BeanPropertyMeta pMeta : bm.getPropertyMetas()) {<a name="line.332"></a>
+<span class="sourceLineNo">333</span>                  XmlFormat pMetaFormat = pMeta.getExtendedMeta(XmlBeanPropertyMeta.class).getXmlFormat();<a name="line.333"></a>
+<span class="sourceLineNo">334</span>                  if (pMetaFormat != XmlFormat.ATTR)<a name="line.334"></a>
+<span class="sourceLineNo">335</span>                     hasChildElements = true;<a name="line.335"></a>
+<span class="sourceLineNo">336</span>               }<a name="line.336"></a>
+<span class="sourceLineNo">337</span><a name="line.337"></a>
+<span class="sourceLineNo">338</span>               XmlBeanMeta xbm2 = bm.getExtendedMeta(XmlBeanMeta.class);<a name="line.338"></a>
+<span class="sourceLineNo">339</span>               if (xbm2.getContentProperty() != null &amp;&amp; xbm2.getContentFormat() == ELEMENTS) {<a name="line.339"></a>
+<span class="sourceLineNo">340</span>                  w.sTag(i+1, "sequence").nl(i+1);<a name="line.340"></a>
+<span class="sourceLineNo">341</span>                  w.oTag(i+2, "any")<a name="line.341"></a>
+<span class="sourceLineNo">342</span>                     .attr("processContents", "skip")<a name="line.342"></a>
+<span class="sourceLineNo">343</span>                     .attr("minOccurs", 0)<a name="line.343"></a>
+<span class="sourceLineNo">344</span>                     .ceTag().nl(i+2);<a name="line.344"></a>
+<span class="sourceLineNo">345</span>                  w.eTag(i+1, "sequence").nl(i+1);<a name="line.345"></a>
 <span class="sourceLineNo">346</span><a name="line.346"></a>
-<span class="sourceLineNo">347</span>                  boolean hasOtherNsElement = false;<a name="line.347"></a>
-<span class="sourceLineNo">348</span>                  boolean hasCollapsed = false;<a name="line.348"></a>
-<span class="sourceLineNo">349</span><a name="line.349"></a>
-<span class="sourceLineNo">350</span>                  for (BeanPropertyMeta pMeta : bm.getPropertyMetas()) {<a name="line.350"></a>
-<span class="sourceLineNo">351</span>                     XmlBeanPropertyMeta xmlMeta = pMeta.getExtendedMeta(XmlBeanPropertyMeta.class);<a name="line.351"></a>
-<span class="sourceLineNo">352</span>                     if (xmlMeta.getXmlFormat() != ATTR) {<a name="line.352"></a>
-<span class="sourceLineNo">353</span>                        if (xmlMeta.getNamespace() != null) {<a name="line.353"></a>
-<span class="sourceLineNo">354</span>                           ClassMeta&lt;?&gt; ct2 = pMeta.getClassMeta();<a name="line.354"></a>
-<span class="sourceLineNo">355</span>                           Namespace cNs = first(xmlMeta.getNamespace(), ct2.getExtendedMeta(XmlClassMeta.class).getNamespace(), cm.getExtendedMeta(XmlClassMeta.class).getNamespace(), defaultNs);<a name="line.355"></a>
-<span class="sourceLineNo">356</span>                           // Child element is in another namespace.<a name="line.356"></a>
-<span class="sourceLineNo">357</span>                           schemas.queueElement(cNs, pMeta.getName(), ct2);<a name="line.357"></a>
-<span class="sourceLineNo">358</span>                           hasOtherNsElement = true;<a name="line.358"></a>
-<span class="sourceLineNo">359</span>                        }<a name="line.359"></a>
-<span class="sourceLineNo">360</span>                        if (xmlMeta.getXmlFormat() == COLLAPSED)<a name="line.360"></a>
-<span class="sourceLineNo">361</span>                           hasCollapsed = true;<a name="line.361"></a>
-<span class="sourceLineNo">362</span>                     }<a name="line.362"></a>
-<span class="sourceLineNo">363</span>                  }<a name="line.363"></a>
-<span class="sourceLineNo">364</span><a name="line.364"></a>
-<span class="sourceLineNo">365</span>                  if (hasOtherNsElement || hasCollapsed) {<a name="line.365"></a>
-<span class="sourceLineNo">366</span>                     // If this bean has any child elements in another namespace,<a name="line.366"></a>
-<span class="sourceLineNo">367</span>                     // we need to add an &lt;any&gt; element.<a name="line.367"></a>
-<span class="sourceLineNo">368</span>                     w.oTag(i+1, "choice").attr("maxOccurs", "unbounded").cTag().nl(i+1);<a name="line.368"></a>
-<span class="sourceLineNo">369</span>                     w.oTag(i+2, "any")<a name="line.369"></a>
-<span class="sourceLineNo">370</span>                        .attr("processContents", "skip")<a name="line.370"></a>
-<span class="sourceLineNo">371</span>                        .attr("minOccurs", 0)<a name="line.371"></a>
-<span class="sourceLineNo">372</span>                        .ceTag().nl(i+2);<a name="line.372"></a>
-<span class="sourceLineNo">373</span>                     w.eTag(i+1, "choice").nl(i+1);<a name="line.373"></a>
-<span class="sourceLineNo">374</span><a name="line.374"></a>
-<span class="sourceLineNo">375</span>                  } else {<a name="line.375"></a>
-<span class="sourceLineNo">376</span>                     w.sTag(i+1, "all").nl(i+1);<a name="line.376"></a>
-<span class="sourceLineNo">377</span>                     for (BeanPropertyMeta pMeta : bm.getPropertyMetas()) {<a name="line.377"></a>
-<span class="sourceLineNo">378</span>                        XmlBeanPropertyMeta xmlMeta = pMeta.getExtendedMeta(XmlBeanPropertyMeta.class);<a name="line.378"></a>
-<span class="sourceLineNo">379</span>                        if (xmlMeta.getXmlFormat() != ATTR) {<a name="line.379"></a>
-<span class="sourceLineNo">380</span>                           boolean isCollapsed = xmlMeta.getXmlFormat() == COLLAPSED;<a name="line.380"></a>
-<span class="sourceLineNo">381</span>                           ClassMeta&lt;?&gt; ct2 = pMeta.getClassMeta();<a name="line.381"></a>
-<span class="sourceLineNo">382</span>                           String childName = pMeta.getName();<a name="line.382"></a>
-<span class="sourceLineNo">383</span>                           if (isCollapsed) {<a name="line.383"></a>
-<span class="sourceLineNo">384</span>                              if (xmlMeta.getChildName() != null)<a name="line.384"></a>
-<span class="sourceLineNo">385</span>                                 childName = xmlMeta.getChildName();<a name="line.385"></a>
-<span class="sourceLineNo">386</span>                              ct2 = pMeta.getClassMeta().getElementType();<a name="line.386"></a>
-<span class="sourceLineNo">387</span>                           }<a name="line.387"></a>
-<span class="sourceLineNo">388</span>                           Namespace cNs = first(xmlMeta.getNamespace(), ct2.getExtendedMeta(XmlClassMeta.class).getNamespace(), cm.getExtendedMeta(XmlClassMeta.class).getNamespace(), defaultNs);<a name="line.388"></a>
-<span class="sourceLineNo">389</span>                           if (xmlMeta.getNamespace() == null) {<a name="line.389"></a>
-<span class="sourceLineNo">390</span>                              w.oTag(i+2, "element")<a name="line.390"></a>
-<span class="sourceLineNo">391</span>                                 .attr("name", XmlUtils.encodeElementName(childName), false)<a name="line.391"></a>
-<span class="sourceLineNo">392</span>                                 .attr("type", getXmlType(cNs, ct2))<a name="line.392"></a>
-<span class="sourceLineNo">393</span>                                 .attr("minOccurs", 0);<a name="line.393"></a>
-<span class="sourceLineNo">394</span><a name="line.394"></a>
-<span class="sourceLineNo">395</span>                              w.ceTag().nl(i+2);<a name="line.395"></a>
-<span class="sourceLineNo">396</span>                           } else {<a name="line.396"></a>
-<span class="sourceLineNo">397</span>                              // Child element is in another namespace.<a name="line.397"></a>
-<span class="sourceLineNo">398</span>                              schemas.queueElement(cNs, pMeta.getName(), ct2);<a name="line.398"></a>
-<span class="sourceLineNo">399</span>                              hasOtherNsElement = true;<a name="line.399"></a>
-<span class="sourceLineNo">400</span>                           }<a name="line.400"></a>
-<span class="sourceLineNo">401</span><a name="line.401"></a>
-<span class="sourceLineNo">402</span>                        }<a name="line.402"></a>
-<span class="sourceLineNo">403</span>                     }<a name="line.403"></a>
-<span class="sourceLineNo">404</span>                     w.eTag(i+1, "all").nl(i+1);<a name="line.404"></a>
-<span class="sourceLineNo">405</span>                  }<a name="line.405"></a>
-<span class="sourceLineNo">406</span><a name="line.406"></a>
-<span class="sourceLineNo">407</span>               }<a name="line.407"></a>
+<span class="sourceLineNo">347</span>               } else if (hasChildElements) {<a name="line.347"></a>
+<span class="sourceLineNo">348</span><a name="line.348"></a>
+<span class="sourceLineNo">349</span>                  boolean hasOtherNsElement = false;<a name="line.349"></a>
+<span class="sourceLineNo">350</span>                  boolean hasCollapsed = false;<a name="line.350"></a>
+<span class="sourceLineNo">351</span><a name="line.351"></a>
+<span class="sourceLineNo">352</span>                  for (BeanPropertyMeta pMeta : bm.getPropertyMetas()) {<a name="line.352"></a>
+<span class="sourceLineNo">353</span>                     XmlBeanPropertyMeta xmlMeta = pMeta.getExtendedMeta(XmlBeanPropertyMeta.class);<a name="line.353"></a>
+<span class="sourceLineNo">354</span>                     if (xmlMeta.getXmlFormat() != ATTR) {<a name="line.354"></a>
+<span class="sourceLineNo">355</span>                        if (xmlMeta.getNamespace() != null) {<a name="line.355"></a>
+<span class="sourceLineNo">356</span>                           ClassMeta&lt;?&gt; ct2 = pMeta.getClassMeta();<a name="line.356"></a>
+<span class="sourceLineNo">357</span>                           Namespace cNs = first(xmlMeta.getNamespace(), ct2.getExtendedMeta(XmlClassMeta.class).getNamespace(), cm.getExtendedMeta(XmlClassMeta.class).getNamespace(), defaultNs);<a name="line.357"></a>
+<span class="sourceLineNo">358</span>                           // Child element is in another namespace.<a name="line.358"></a>
+<span class="sourceLineNo">359</span>                           schemas.queueElement(cNs, pMeta.getName(), ct2);<a name="line.359"></a>
+<span class="sourceLineNo">360</span>                           hasOtherNsElement = true;<a name="line.360"></a>
+<span class="sourceLineNo">361</span>                        }<a name="line.361"></a>
+<span class="sourceLineNo">362</span>                        if (xmlMeta.getXmlFormat() == COLLAPSED)<a name="line.362"></a>
+<span class="sourceLineNo">363</span>                           hasCollapsed = true;<a name="line.363"></a>
+<span class="sourceLineNo">364</span>                     }<a name="line.364"></a>
+<span class="sourceLineNo">365</span>                  }<a name="line.365"></a>
+<span class="sourceLineNo">366</span><a name="line.366"></a>
+<span class="sourceLineNo">367</span>                  if (hasOtherNsElement || hasCollapsed) {<a name="line.367"></a>
+<span class="sourceLineNo">368</span>                     // If this bean has any child elements in another namespace,<a name="line.368"></a>
+<span class="sourceLineNo">369</span>                     // we need to add an &lt;any&gt; element.<a name="line.369"></a>
+<span class="sourceLineNo">370</span>                     w.oTag(i+1, "choice").attr("maxOccurs", "unbounded").cTag().nl(i+1);<a name="line.370"></a>
+<span class="sourceLineNo">371</span>                     w.oTag(i+2, "any")<a name="line.371"></a>
+<span class="sourceLineNo">372</span>                        .attr("processContents", "skip")<a name="line.372"></a>
+<span class="sourceLineNo">373</span>                        .attr("minOccurs", 0)<a name="line.373"></a>
+<span class="sourceLineNo">374</span>                        .ceTag().nl(i+2);<a name="line.374"></a>
+<span class="sourceLineNo">375</span>                     w.eTag(i+1, "choice").nl(i+1);<a name="line.375"></a>
+<span class="sourceLineNo">376</span><a name="line.376"></a>
+<span class="sourceLineNo">377</span>                  } else {<a name="line.377"></a>
+<span class="sourceLineNo">378</span>                     w.sTag(i+1, "all").nl(i+1);<a name="line.378"></a>
+<span class="sourceLineNo">379</span>                     for (BeanPropertyMeta pMeta : bm.getPropertyMetas()) {<a name="line.379"></a>
+<span class="sourceLineNo">380</span>                        XmlBeanPropertyMeta xmlMeta = pMeta.getExtendedMeta(XmlBeanPropertyMeta.class);<a name="line.380"></a>
+<span class="sourceLineNo">381</span>                        if (xmlMeta.getXmlFormat() != ATTR) {<a name="line.381"></a>
+<span class="sourceLineNo">382</span>                           boolean isCollapsed = xmlMeta.getXmlFormat() == COLLAPSED;<a name="line.382"></a>
+<span class="sourceLineNo">383</span>                           ClassMeta&lt;?&gt; ct2 = pMeta.getClassMeta();<a name="line.383"></a>
+<span class="sourceLineNo">384</span>                           String childName = pMeta.getName();<a name="line.384"></a>
+<span class="sourceLineNo">385</span>                           if (isCollapsed) {<a name="line.385"></a>
+<span class="sourceLineNo">386</span>                              if (xmlMeta.getChildName() != null)<a name="line.386"></a>
+<span class="sourceLineNo">387</span>                                 childName = xmlMeta.getChildName();<a name="line.387"></a>
+<span class="sourceLineNo">388</span>                              ct2 = pMeta.getClassMeta().getElementType();<a name="line.388"></a>
+<span class="sourceLineNo">389</span>                           }<a name="line.389"></a>
+<span class="sourceLineNo">390</span>                           Namespace cNs = first(xmlMeta.getNamespace(), ct2.getExtendedMeta(XmlClassMeta.class).getNamespace(), cm.getExtendedMeta(XmlClassMeta.class).getNamespace(), defaultNs);<a name="line.390"></a>
+<span class="sourceLineNo">391</span>                           if (xmlMeta.getNamespace() == null) {<a name="line.391"></a>
+<span class="sourceLineNo">392</span>                              w.oTag(i+2, "element")<a name="line.392"></a>
+<span class="sourceLineNo">393</span>                                 .attr("name", XmlUtils.encodeElementName(childName), false)<a name="line.393"></a>
+<span class="sourceLineNo">394</span>                                 .attr("type", getXmlType(cNs, ct2))<a name="line.394"></a>
+<span class="sourceLineNo">395</span>                                 .attr("minOccurs", 0);<a name="line.395"></a>
+<span class="sourceLineNo">396</span><a name="line.396"></a>
+<span class="sourceLineNo">397</span>                              w.ceTag().nl(i+2);<a name="line.397"></a>
+<span class="sourceLineNo">398</span>                           } else {<a name="line.398"></a>
+<span class="sourceLineNo">399</span>                              // Child element is in another namespace.<a name="line.399"></a>
+<span class="sourceLineNo">400</span>                              schemas.queueElement(cNs, pMeta.getName(), ct2);<a name="line.400"></a>
+<span class="sourceLineNo">401</span>                              hasOtherNsElement = true;<a name="line.401"></a>
+<span class="sourceLineNo">402</span>                           }<a name="line.402"></a>
+<span class="sourceLineNo">403</span><a name="line.403"></a>
+<span class="sourceLineNo">404</span>                        }<a name="line.404"></a>
+<span class="sourceLineNo">405</span>                     }<a name="line.405"></a>
+<span class="sourceLineNo">406</span>                     w.eTag(i+1, "all").nl(i+1);<a name="line.406"></a>
+<span class="sourceLineNo">407</span>                  }<a name="line.407"></a>
 <span class="sourceLineNo">408</span><a name="line.408"></a>
-<span class="sourceLineNo">409</span>               for (BeanPropertyMeta pMeta : bm.getExtendedMeta(XmlBeanMeta.class).getAttrProperties().values()) {<a name="line.409"></a>
-<span class="sourceLineNo">410</span>                  Namespace pNs = pMeta.getExtendedMeta(XmlBeanPropertyMeta.class).getNamespace();<a name="line.410"></a>
-<span class="sourceLineNo">411</span>                  if (pNs == null)<a name="line.411"></a>
-<span class="sourceLineNo">412</span>                     pNs = defaultNs;<a name="line.412"></a>
-<span class="sourceLineNo">413</span><a name="line.413"></a>
-<span class="sourceLineNo">414</span>                  // If the bean attribute has a different namespace than the bean, then it needs to<a name="line.414"></a>
-<span class="sourceLineNo">415</span>                  // be added as a top-level entry in the appropriate schema file.<a name="line.415"></a>
-<span class="sourceLineNo">416</span>                  if (pNs != targetNs) {<a name="line.416"></a>
-<span class="sourceLineNo">417</span>                     schemas.queueAttribute(pNs, pMeta.getName(), pMeta.getClassMeta());<a name="line.417"></a>
-<span class="sourceLineNo">418</span>                     w.oTag(i+1, "attribute")<a name="line.418"></a>
-<span class="sourceLineNo">419</span>                        //.attr("name", pMeta.getName(), true)<a name="line.419"></a>
-<span class="sourceLineNo">420</span>                        .attr("ref", pNs.getName() + ':' + pMeta.getName())<a name="line.420"></a>
-<span class="sourceLineNo">421</span>                        .ceTag().nl(i+1);<a name="line.421"></a>
-<span class="sourceLineNo">422</span>                  }<a name="line.422"></a>
-<span class="sourceLineNo">423</span><a name="line.423"></a>
-<span class="sourceLineNo">424</span>                  // Otherwise, it's just a plain attribute of this bean.<a name="line.424"></a>
-<span class="sourceLineNo">425</span>                  else {<a name="line.425"></a>
-<span class="sourceLineNo">426</span>                     w.oTag(i+1, "attribute")<a name="line.426"></a>
-<span class="sourceLineNo">427</span>                        .attr("name", pMeta.getName(), true)<a name="line.427"></a>
-<span class="sourceLineNo">428</span>                        .attr("type", getXmlAttrType(pMeta.getClassMeta()))<a name="line.428"></a>
-<span class="sourceLineNo">429</span>                        .ceTag().nl(i+1);<a name="line.429"></a>
-<span class="sourceLineNo">430</span>                  }<a name="line.430"></a>
-<span class="sourceLineNo">431</span>               }<a name="line.431"></a>
-<span class="sourceLineNo">432</span><a name="line.432"></a>
-<span class="sourceLineNo">433</span>            //----- Collection -----<a name="line.433"></a>
-<span class="sourceLineNo">434</span>            } else if (cm.isCollectionOrArray()) {<a name="line.434"></a>
-<span class="sourceLineNo">435</span>               ClassMeta&lt;?&gt; elementType = cm.getElementType();<a name="line.435"></a>
-<span class="sourceLineNo">436</span>               if (elementType.isObject()) {<a name="line.436"></a>
-<span class="sourceLineNo">437</span>                  w.sTag(i+1, "sequence").nl(i+1);<a name="line.437"></a>
-<span class="sourceLineNo">438</span>                  w.oTag(i+2, "any")<a name="line.438"></a>
-<span class="sourceLineNo">439</span>                     .attr("processContents", "skip")<a name="line.439"></a>
-<span class="sourceLineNo">440</span>                     .attr("maxOccurs", "unbounded")<a name="line.440"></a>
-<span class="sourceLineNo">441</span>                     .attr("minOccurs", "0")<a name="line.441"></a>
-<span class="sourceLineNo">442</span>                     .ceTag().nl(i+2);<a name="line.442"></a>
-<span class="sourceLineNo">443</span>                  w.eTag(i+1, "sequence").nl(i+1);<a name="line.443"></a>
-<span class="sourceLineNo">444</span>               } else {<a name="line.444"></a>
-<span class="sourceLineNo">445</span>                  Namespace cNs = first(elementType.getExtendedMeta(XmlClassMeta.class).getNamespace(), cm.getExtendedMeta(XmlClassMeta.class).getNamespace(), defaultNs);<a name="line.445"></a>
-<span class="sourceLineNo">446</span>                  schemas.queueType(cNs, null, elementType);<a name="line.446"></a>
-<span class="sourceLineNo">447</span>                  w.sTag(i+1, "sequence").nl(i+1);<a name="line.447"></a>
-<span class="sourceLineNo">448</span>                  w.oTag(i+2, "any")<a name="line.448"></a>
-<span class="sourceLineNo">449</span>                     .attr("processContents", "skip")<a name="line.449"></a>
-<span class="sourceLineNo">450</span>                     .attr("maxOccurs", "unbounded")<a name="line.450"></a>
-<span class="sourceLineNo">451</span>                     .attr("minOccurs", "0")<a name="line.451"></a>
-<span class="sourceLineNo">452</span>                     .ceTag().nl(i+2);<a name="line.452"></a>
-<span class="sourceLineNo">453</span>                  w.eTag(i+1, "sequence").nl(i+1);<a name="line.453"></a>
-<span class="sourceLineNo">454</span>               }<a name="line.454"></a>
-<span class="sourceLineNo">455</span><a name="line.455"></a>
-<span class="sourceLineNo">456</span>            //----- Map -----<a name="line.456"></a>
-<span class="sourceLineNo">457</span>            } else if (cm.isMap() || cm.isAbstract() || cm.isObject()) {<a name="line.457"></a>
-<span class="sourceLineNo">458</span>               w.sTag(i+1, "sequence").nl(i+1);<a name="line.458"></a>
-<span class="sourceLineNo">459</span>               w.oTag(i+2, "any")<a name="line.459"></a>
-<span class="sourceLineNo">460</span>                  .attr("processContents", "skip")<a name="line.460"></a>
-<span class="sourceLineNo">461</span>                  .attr("maxOccurs", "unbounded")<a name="line.461"></a>
-<span class="sourceLineNo">462</span>                  .attr("minOccurs", "0")<a name="line.462"></a>
-<span class="sourceLineNo">463</span>                  .ceTag().nl(i+2);<a name="line.463"></a>
-<span class="sourceLineNo">464</span>               w.eTag(i+1, "sequence").nl(i+1);<a name="line.464"></a>
-<span class="sourceLineNo">465</span>            }<a name="line.465"></a>
-<span class="sourceLineNo">466</span><a name="line.466"></a>
-<span class="sourceLineNo">467</span>            w.oTag(i+1, "attribute")<a name="line.467"></a>
-<span class="sourceLineNo">468</span>               .attr("name", getBeanTypePropertyName(null))<a name="line.468"></a>
-<span class="sourceLineNo">469</span>               .attr("type", "string")<a name="line.469"></a>
-<span class="sourceLineNo">470</span>               .ceTag().nl(i+1);<a name="line.470"></a>
-<span class="sourceLineNo">471</span>         }<a name="line.471"></a>
-<span class="sourceLineNo">472</span><a name="line.472"></a>
-<span class="sourceLineNo">473</span>         w.eTag(i, "complexType").nl(i);<a name="line.473"></a>
-<span class="sourceLineNo">474</span>         schemas.processQueue();<a name="line.474"></a>
-<span class="sourceLineNo">475</span><a name="line.475"></a>
-<span class="sourceLineNo">476</span>         return true;<a name="line.476"></a>
-<span class="sourceLineNo">477</span>      }<a name="line.477"></a>
-<span class="sourceLineNo">478</span><a name="line.478"></a>
-<span class="sourceLineNo">479</span>      private String getElementName(ClassMeta&lt;?&gt; cm) {<a name="line.479"></a>
-<span class="sourceLineNo">480</span>         cm = cm.getSerializedClassMeta();<a name="line.480"></a>
-<span class="sourceLineNo">481</span>         String name = cm.getDictionaryName();<a name="line.481"></a>
-<span class="sourceLineNo">482</span><a name="line.482"></a>
-<span class="sourceLineNo">483</span>         if (name == null) {<a name="line.483"></a>
-<span class="sourceLineNo">484</span>            if (cm.isBoolean())<a name="line.484"></a>
-<span class="sourceLineNo">485</span>               name = "boolean";<a name="line.485"></a>
-<span class="sourceLineNo">486</span>            else if (cm.isNumber())<a name="line.486"></a>
-<span class="sourceLineNo">487</span>               name = "number";<a name="line.487"></a>
-<span class="sourceLineNo">488</span>            else if (cm.isCollectionOrArray())<a name="line.488"></a>
-<span class="sourceLineNo">489</span>               name = "array";<a name="line.489"></a>
-<span class="sourceLineNo">490</span>            else if (! (cm.isMapOrBean() || cm.isCollectionOrArray() || cm.isObject() || cm.isAbstract()))<a name="line.490"></a>
-<span class="sourceLineNo">491</span>               name = "string";<a name="line.491"></a>
-<span class="sourceLineNo">492</span>            else<a name="line.492"></a>
-<span class="sourceLineNo">493</span>               name = "object";<a name="line.493"></a>
-<span class="sourceLineNo">494</span>         }<a name="line.494"></a>
-<span class="sourceLineNo">495</span>         return name;<a name="line.495"></a>
-<span class="sourceLineNo">496</span>      }<a name="line.496"></a>
-<span class="sourceLineNo">497</span><a name="line.497"></a>
-<span class="sourceLineNo">498</span>      @Override /* Object */<a name="line.498"></a>
-<span class="sourceLineNo">499</span>      public String toString() {<a name="line.499"></a>
-<span class="sourceLineNo">500</span>         try {<a name="line.500"></a>
-<span class="sourceLineNo">501</span>            w.eTag(indent, "schema").nl(indent);<a name="line.501"></a>
-<span class="sourceLineNo">502</span>         } catch (IOException e) {<a name="line.502"></a>
-<span class="sourceLineNo">503</span>            throw new RuntimeException(e); // Shouldn't happen.<a name="line.503"></a>
-<span class="sourceLineNo">504</span>         }<a name="line.504"></a>
-<span class="sourceLineNo">505</span>         return sw.toString();<a name="line.505"></a>
-<span class="sourceLineNo">506</span>      }<a name="line.506"></a>
-<span class="sourceLineNo">507</span><a name="line.507"></a>
-<span class="sourceLineNo">508</span>      private String getXmlType(Namespace currentNs, ClassMeta&lt;?&gt; cm) {<a name="line.508"></a>
-<span class="sourceLineNo">509</span>         String name = null;<a name="line.509"></a>
-<span class="sourceLineNo">510</span>         cm = cm.getSerializedClassMeta();<a name="line.510"></a>
-<span class="sourceLineNo">511</span>         if (currentNs == targetNs) {<a name="line.511"></a>
-<span class="sourceLineNo">512</span>            if (cm.isPrimitive()) {<a name="line.512"></a>
-<span class="sourceLineNo">513</span>               if (cm.isBoolean())<a name="line.513"></a>
-<span class="sourceLineNo">514</span>                  name = "boolean";<a name="line.514"></a>
-<span class="sourceLineNo">515</span>               else if (cm.isNumber()) {<a name="line.515"></a>
-<span class="sourceLineNo">516</span>                  if (cm.isDecimal())<a name="line.516"></a>
-<span class="sourceLineNo">517</span>                     name = "decimal";<a name="line.517"></a>
-<span class="sourceLineNo">518</span>                  else<a name="line.518"></a>
-<span class="sourceLineNo">519</span>                     name = "integer";<a name="line.519"></a>
-<span class="sourceLineNo">520</span>               }<a name="line.520"></a>
-<span class="sourceLineNo">521</span>            }<a name="line.521"></a>
-<span class="sourceLineNo">522</span>         }<a name="line.522"></a>
-<span class="sourceLineNo">523</span>         if (name == null) {<a name="line.523"></a>
-<span class="sourceLineNo">524</span>            name = XmlUtils.encodeElementName(cm);<a name="line.524"></a>
-<span class="sourceLineNo">525</span>            schemas.queueType(currentNs, name, cm);<a name="line.525"></a>
-<span class="sourceLineNo">526</span>            return currentNs.getName() + ":" + name;<a name="line.526"></a>
-<span class="sourceLineNo">527</span>         }<a name="line.527"></a>
-<span class="sourceLineNo">528</span><a name="line.528"></a>
-<span class="sourceLineNo">529</span>         return name;<a name="line.529"></a>
-<span class="sourceLineNo">530</span>      }<a name="line.530"></a>
-<span class="sourceLineNo">531</span>   }<a name="line.531"></a>
-<span class="sourceLineNo">532</span><a name="line.532"></a>
-<span class="sourceLineNo">533</span>   private static &lt;T&gt; T first(T...tt) {<a name="line.533"></a>
-<span class="sourceLineNo">534</span>      for (T t : tt)<a name="line.534"></a>
-<span class="sourceLineNo">535</span>         if (t != null)<a name="line.535"></a>
-<span class="sourceLineNo">536</span>            return t;<a name="line.536"></a>
-<span class="sourceLineNo">537</span>      return null;<a name="line.537"></a>
-<span class="sourceLineNo">538</span>   }<a name="line.538"></a>
-<span class="sourceLineNo">539</span><a name="line.539"></a>
-<span class="sourceLineNo">540</span>   private static String getXmlAttrType(ClassMeta&lt;?&gt; cm) {<a name="line.540"></a>
-<span class="sourceLineNo">541</span>      if (cm.isBoolean())<a name="line.541"></a>
-<span class="sourceLineNo">542</span>         return "boolean";<a name="line.542"></a>
-<span class="sourceLineNo">543</span>      if (cm.isNumber()) {<a name="line.543"></a>
-<span class="sourceLineNo">544</span>         if (cm.isDecimal())<a name="line.544"></a>
-<span class="sourceLineNo">545</span>            return "decimal";<a name="line.545"></a>
-<span class="sourceLineNo">546</span>         return "integer";<a name="line.546"></a>
-<span class="sourceLineNo">547</span>      }<a name="line.547"></a>
-<span class="sourceLineNo">548</span>      return "string";<a name="line.548"></a>
-<span class="sourceLineNo">549</span>   }<a name="line.549"></a>
-<span class="sourceLineNo">550</span>}<a name="line.550"></a>
+<span class="sourceLineNo">409</span>               }<a name="line.409"></a>
+<span class="sourceLineNo">410</span><a name="line.410"></a>
+<span class="sourceLineNo">411</span>               for (BeanPropertyMeta pMeta : bm.getExtendedMeta(XmlBeanMeta.class).getAttrProperties().values()) {<a name="line.411"></a>
+<span class="sourceLineNo">412</span>                  Namespace pNs = pMeta.getExtendedMeta(XmlBeanPropertyMeta.class).getNamespace();<a name="line.412"></a>
+<span class="sourceLineNo">413</span>                  if (pNs == null)<a name="line.413"></a>
+<span class="sourceLineNo">414</span>                     pNs = defaultNs;<a name="line.414"></a>
+<span class="sourceLineNo">415</span><a name="line.415"></a>
+<span class="sourceLineNo">416</span>                  // If the bean attribute has a different namespace than the bean, then it needs to<a name="line.416"></a>
+<span class="sourceLineNo">417</span>                  // be added as a top-level entry in the appropriate schema file.<a name="line.417"></a>
+<span class="sourceLineNo">418</span>                  if (pNs != targetNs) {<a name="line.418"></a>
+<span class="sourceLineNo">419</span>                     schemas.queueAttribute(pNs, pMeta.getName(), pMeta.getClassMeta());<a name="line.419"></a>
+<span class="sourceLineNo">420</span>                     w.oTag(i+1, "attribute")<a name="line.420"></a>
+<span class="sourceLineNo">421</span>                        //.attr("name", pMeta.getName(), true)<a name="line.421"></a>
+<span class="sourceLineNo">422</span>                        .attr("ref", pNs.getName() + ':' + pMeta.getName())<a name="line.422"></a>
+<span class="sourceLineNo">423</span>                        .ceTag().nl(i+1);<a name="line.423"></a>
+<span class="sourceLineNo">424</span>                  }<a name="line.424"></a>
+<span class="sourceLineNo">425</span><a name="line.425"></a>
+<span class="sourceLineNo">426</span>                  // Otherwise, it's just a plain attribute of this bean.<a name="line.426"></a>
+<span class="sourceLineNo">427</span>                  else {<a name="line.427"></a>
+<span class="sourceLineNo">428</span>                     w.oTag(i+1, "attribute")<a name="line.428"></a>
+<span class="sourceLineNo">429</span>                        .attr("name", pMeta.getName(), true)<a name="line.429"></a>
+<span class="sourceLineNo">430</span>                        .attr("type", getXmlAttrType(pMeta.getClassMeta()))<a name="line.430"></a>
+<span class="sourceLineNo">431</span>                        .ceTag().nl(i+1);<a name="line.431"></a>
+<span class="sourceLineNo">432</span>                  }<a name="line.432"></a>
+<span class="sourceLineNo">433</span>               }<a name="line.433"></a>
+<span class="sourceLineNo">434</span><a name="line.434"></a>
+<span class="sourceLineNo">435</span>            //----- Collection -----<a name="line.435"></a>
+<span class="sourceLineNo">436</span>            } else if (cm.isCollectionOrArray()) {<a name="line.436"></a>
+<span class="sourceLineNo">437</span>               ClassMeta&lt;?&gt; elementType = cm.getElementType();<a name="line.437"></a>
+<span class="sourceLineNo">438</span>               if (elementType.isObject()) {<a name="line.438"></a>
+<span class="sourceLineNo">439</span>                  w.sTag(i+1, "sequence").nl(i+1);<a name="line.439"></a>
+<span class="sourceLineNo">440</span>                  w.oTag(i+2, "any")<a name="line.440"></a>
+<span class="sourceLineNo">441</span>                     .attr("processContents", "skip")<a name="line.441"></a>
+<span class="sourceLineNo">442</span>                     .attr("maxOccurs", "unbounded")<a name="line.442"></a>
+<span class="sourceLineNo">443</span>                     .attr("minOccurs", "0")<a name="line.443"></a>
+<span class="sourceLineNo">444</span>                     .ceTag().nl(i+2);<a name="line.444"></a>
+<span class="sourceLineNo">445</span>                  w.eTag(i+1, "sequence").nl(i+1);<a name="line.445"></a>
+<span class="sourceLineNo">446</span>               } else {<a name="line.446"></a>
+<span class="sourceLineNo">447</span>                  Namespace cNs = first(elementType.getExtendedMeta(XmlClassMeta.class).getNamespace(), cm.getExtendedMeta(XmlClassMeta.class).getNamespace(), defaultNs);<a name="line.447"></a>
+<span class="sourceLineNo">448</span>                  schemas.queueType(cNs, null, elementType);<a name="line.448"></a>
+<span class="sourceLineNo">449</span>                  w.sTag(i+1, "sequence").nl(i+1);<a name="line.449"></a>
+<span class="sourceLineNo">450</span>                  w.oTag(i+2, "any")<a name="line.450"></a>
+<span class="sourceLineNo">451</span>                     .attr("processContents", "skip")<a name="line.451"></a>
+<span class="sourceLineNo">452</span>                     .attr("maxOccurs", "unbounded")<a name="line.452"></a>
+<span class="sourceLineNo">453</span>                     .attr("minOccurs", "0")<a name="line.453"></a>
+<span class="sourceLineNo">454</span>                     .ceTag().nl(i+2);<a name="line.454"></a>
+<span class="sourceLineNo">455</span>                  w.eTag(i+1, "sequence").nl(i+1);<a name="line.455"></a>
+<span class="sourceLineNo">456</span>               }<a name="line.456"></a>
+<span class="sourceLineNo">457</span><a name="line.457"></a>
+<span class="sourceLineNo">458</span>            //----- Map -----<a name="line.458"></a>
+<span class="sourceLineNo">459</span>            } else if (cm.isMap() || cm.isAbstract() || cm.isObject()) {<a name="line.459"></a>
+<span class="sourceLineNo">460</span>               w.sTag(i+1, "sequence").nl(i+1);<a name="line.460"></a>
+<span class="sourceLineNo">461</span>               w.oTag(i+2, "any")<a name="line.461"></a>
+<span class="sourceLineNo">462</span>                  .attr("processContents", "skip")<a name="line.462"></a>
+<span class="sourceLineNo">463</span>                  .attr("maxOccurs", "unbounded")<a name="line.463"></a>
+<span class="sourceLineNo">464</span>                  .attr("minOccurs", "0")<a name="line.464"></a>
+<span class="sourceLineNo">465</span>                  .ceTag().nl(i+2);<a name="line.465"></a>
+<span class="sourceLineNo">466</span>               w.eTag(i+1, "sequence").nl(i+1);<a name="line.466"></a>
+<span class="sourceLineNo">467</span>            }<a name="line.467"></a>
+<span class="sourceLineNo">468</span><a name="line.468"></a>
+<span class="sourceLineNo">469</span>            w.oTag(i+1, "attribute")<a name="line.469"></a>
+<span class="sourceLineNo">470</span>               .attr("name", getBeanTypePropertyName(null))<a name="line.470"></a>
+<span class="sourceLineNo">471</span>               .attr("type", "string")<a name="line.471"></a>
+<span class="sourceLineNo">472</span>               .ceTag().nl(i+1);<a name="line.472"></a>
+<span class="sourceLineNo">473</span>         }<a name="line.473"></a>
+<span class="sourceLineNo">474</span><a name="line.474"></a>
+<span class="sourceLineNo">475</span>         w.eTag(i, "complexType").nl(i);<a name="line.475"></a>
+<span class="sourceLineNo">476</span>         schemas.processQueue();<a name="line.476"></a>
+<span class="sourceLineNo">477</span><a name="line.477"></a>
+<span class="sourceLineNo">478</span>         return true;<a name="line.478"></a>
+<span class="sourceLineNo">479</span>      }<a name="line.479"></a>
+<span class="sourceLineNo">480</span><a name="line.480"></a>
+<span class="sourceLineNo">481</span>      private String getElementName(ClassMeta&lt;?&gt; cm) {<a name="line.481"></a>
+<span class="sourceLineNo">482</span>         cm = cm.getSerializedClassMeta(schemas.session);<a name="line.482"></a>
+<span class="sourceLineNo">483</span>         String name = cm.getDictionaryName();<a name="line.483"></a>
+<span class="sourceLineNo">484</span><a name="line.484"></a>
+<span class="sourceLineNo">485</span>         if (name == null) {<a name="line.485"></a>
+<span class="sourceLineNo">486</span>            if (cm.isBoolean())<a name="line.486"></a>
+<span class="sourceLineNo">487</span>               name = "boolean";<a name="line.487"></a>
+<span class="sourceLineNo">488</span>            else if (cm.isNumber())<a name="line.488"></a>
+<span class="sourceLineNo">489</span>               name = "number";<a name="line.489"></a>
+<span class="sourceLineNo">490</span>            else if (cm.isCollectionOrArray())<a name="line.490"></a>
+<span class="sourceLineNo">491</span>               name = "array";<a name="line.491"></a>
+<span class="sourceLineNo">492</span>            else if (! (cm.isMapOrBean() || cm.isCollectionOrArray() || cm.isObject() || cm.isAbstract()))<a name="line.492"></a>
+<span class="sourceLineNo">493</span>               name = "string";<a name="line.493"></a>
+<span class="sourceLineNo">494</span>            else<a name="line.494"></a>
+<span class="sourceLineNo">495</span>               name = "object";<a name="line.495"></a>
+<span class="sourceLineNo">496</span>         }<a name="line.496"></a>
+<span class="sourceLineNo">497</span>         return name;<a name="line.497"></a>
+<span class="sourceLineNo">498</span>      }<a name="line.498"></a>
+<span class="sourceLineNo">499</span><a name="line.499"></a>
+<span class="sourceLineNo">500</span>      @Override /* Object */<a name="line.500"></a>
+<span class="sourceLineNo">501</span>      public String toString() {<a name="line.501"></a>
+<span class="sourceLineNo">502</span>         try {<a name="line.502"></a>
+<span class="sourceLineNo">503</span>            w.eTag(indent, "schema").nl(indent);<a name="line.503"></a>
+<span class="sourceLineNo">504</span>         } catch (IOException e) {<a name="line.504"></a>
+<span class="sourceLineNo">505</span>            throw new RuntimeException(e); // Shouldn't happen.<a name="line.505"></a>
+<span class="sourceLineNo">506</span>         }<a name="line.506"></a>
+<span class="sourceLineNo">507</span>         return sw.toString();<a name="line.507"></a>
+<span class="sourceLineNo">508</span>      }<a name="line.508"></a>
+<span class="sourceLineNo">509</span><a name="line.509"></a>
+<span class="sourceLineNo">510</span>      private String getXmlType(Namespace currentNs, ClassMeta&lt;?&gt; cm) {<a name="line.510"></a>
+<span class="sourceLineNo">511</span>         String name = null;<a name="line.511"></a>
+<span class="sourceLineNo">512</span>         cm = cm.getSerializedClassMeta(schemas.session);<a name="line.512"></a>
+<span class="sourceLineNo">513</span>         if (currentNs == targetNs) {<a name="line.513"></a>
+<span class="sourceLineNo">514</span>            if (cm.isPrimitive()) {<a name="line.514"></a>
+<span class="sourceLineNo">515</span>               if (cm.isBoolean())<a name="line.515"></a>
+<span class="sourceLineNo">516</span>                  name = "boolean";<a name="line.516"></a>
+<span class="sourceLineNo">517</span>               else if (cm.isNumber()) {<a name="line.517"></a>
+<span class="sourceLineNo">518</span>                  if (cm.isDecimal())<a name="line.518"></a>
+<span class="sourceLineNo">519</span>                     name = "decimal";<a name="line.519"></a>
+<span class="sourceLineNo">520</span>                  else<a name="line.520"></a>
+<span class="sourceLineNo">521</span>                     name = "integer";<a name="line.521"></a>
+<span class="sourceLineNo">522</span>               }<a name="line.522"></a>
+<span class="sourceLineNo">523</span>            }<a name="line.523"></a>
+<span class="sourceLineNo">524</span>         }<a name="line.524"></a>
+<span class="sourceLineNo">525</span>         if (name == null) {<a name="line.525"></a>
+<span class="sourceLineNo">526</span>            name = XmlUtils.encodeElementName(cm);<a name="line.526"></a>
+<span class="sourceLineNo">527</span>            schemas.queueType(currentNs, name, cm);<a name="line.527"></a>
+<span class="sourceLineNo">528</span>            return currentNs.getName() + ":" + name;<a name="line.528"></a>
+<span class="sourceLineNo">529</span>         }<a name="line.529"></a>
+<span class="sourceLineNo">530</span><a name="line.530"></a>
+<span class="sourceLineNo">531</span>         return name;<a name="line.531"></a>
+<span class="sourceLineNo">532</span>      }<a name="line.532"></a>
+<span class="sourceLineNo">533</span>   }<a name="line.533"></a>
+<span class="sourceLineNo">534</span><a name="line.534"></a>
+<span class="sourceLineNo">535</span>   private static &lt;T&gt; T first(T...tt) {<a name="line.535"></a>
+<span class="sourceLineNo">536</span>      for (T t : tt)<a name="line.536"></a>
+<span class="sourceLineNo">537</span>         if (t != null)<a name="line.537"></a>
+<span class="sourceLineNo">538</span>            return t;<a name="line.538"></a>
+<span class="sourceLineNo">539</span>      return null;<a name="line.539"></a>
+<span class="sourceLineNo">540</span>   }<a name="line.540"></a>
+<span class="sourceLineNo">541</span><a name="line.541"></a>
+<span class="sourceLineNo">542</span>   private static String getXmlAttrType(ClassMeta&lt;?&gt; cm) {<a name="line.542"></a>
+<span class="sourceLineNo">543</span>      if (cm.isBoolean())<a name="line.543"></a>
+<span class="sourceLineNo">544</span>         return "boolean";<a name="line.544"></a>
+<span class="sourceLineNo">545</span>      if (cm.isNumber()) {<a name="line.545"></a>
+<span class="sourceLineNo">546</span>         if (cm.isDecimal())<a name="line.546"></a>
+<span class="sourceLineNo">547</span>            return "decimal";<a name="line.547"></a>
+<span class="sourceLineNo">548</span>         return "integer";<a name="line.548"></a>
+<span class="sourceLineNo">549</span>      }<a name="line.549"></a>
+<span class="sourceLineNo">550</span>      return "string";<a name="line.550"></a>
+<span class="sourceLineNo">551</span>   }<a name="line.551"></a>
+<span class="sourceLineNo">552</span>}<a name="line.552"></a>
 
 
 


Mime
View raw message