01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.databinding.source;
19:
20: import java.util.Collection;
21:
22: import javax.xml.transform.dom.DOMSource;
23:
24: import org.w3c.dom.Document;
25: import org.w3c.dom.Element;
26: import org.w3c.dom.Node;
27: import org.w3c.dom.NodeList;
28:
29: import org.apache.cxf.common.util.StringUtils;
30: import org.apache.cxf.service.model.SchemaInfo;
31: import org.apache.cxf.service.model.ServiceInfo;
32: import org.apache.ws.commons.schema.XmlSchema;
33: import org.apache.ws.commons.schema.XmlSchemaCollection;
34:
35: public class AbstractDataBinding {
36: private Collection<DOMSource> schemas;
37:
38: public Collection<DOMSource> getSchemas() {
39: return schemas;
40: }
41:
42: public void setSchemas(Collection<DOMSource> schemas) {
43: this .schemas = schemas;
44: }
45:
46: protected void addSchemaDocument(ServiceInfo serviceInfo,
47: XmlSchemaCollection col, Document d, String systemId) {
48: String ns = d.getDocumentElement().getAttribute(
49: "targetNamespace");
50: if (StringUtils.isEmpty(ns)) {
51: ns = serviceInfo.getInterface().getName().getNamespaceURI();
52: d.getDocumentElement().setAttribute("targetNamespace", ns);
53: }
54:
55: NodeList nodes = d.getDocumentElement().getChildNodes();
56: for (int i = 0; i < nodes.getLength(); i++) {
57: Node n = nodes.item(i);
58: if (n instanceof Element) {
59: Element e = (Element) n;
60: if (e.getLocalName().equals("import")) {
61: d.getDocumentElement().removeChild(e);
62: }
63: }
64: }
65:
66: SchemaInfo schema = new SchemaInfo(serviceInfo, ns);
67: schema.setElement(d.getDocumentElement());
68: schema.setSystemId(systemId);
69: XmlSchema xmlSchema = col.read(d.getDocumentElement());
70: schema.setSchema(xmlSchema);
71: serviceInfo.addSchema(schema);
72: }
73: }
|