001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.service.model;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.concurrent.ConcurrentHashMap;
026:
027: import javax.xml.namespace.QName;
028: import org.apache.ws.commons.schema.XmlSchemaCollection;
029:
030: public class ServiceInfo extends AbstractDescriptionElement {
031: QName name;
032: String targetNamespace;
033: InterfaceInfo intf;
034: Map<QName, BindingInfo> bindings = new ConcurrentHashMap<QName, BindingInfo>(
035: 2);
036: Map<QName, EndpointInfo> endpoints = new ConcurrentHashMap<QName, EndpointInfo>(
037: 2);
038: Map<QName, MessageInfo> messages;
039: List<SchemaInfo> schemas = new ArrayList<SchemaInfo>(4);
040: private XmlSchemaCollection xmlSchemaCollection;
041:
042: public ServiceInfo() {
043: }
044:
045: public String getTargetNamespace() {
046: return targetNamespace;
047: }
048:
049: public void setTargetNamespace(String ns) {
050: targetNamespace = ns;
051: }
052:
053: public void setName(QName n) {
054: name = n;
055: }
056:
057: public QName getName() {
058: return name;
059: }
060:
061: public InterfaceInfo createInterface(QName qn) {
062: intf = new InterfaceInfo(this , qn);
063: return intf;
064: }
065:
066: public void setInterface(InterfaceInfo inf) {
067: intf = inf;
068: }
069:
070: public InterfaceInfo getInterface() {
071: return intf;
072: }
073:
074: public BindingInfo getBinding(QName qn) {
075: return bindings.get(qn);
076: }
077:
078: public void addBinding(BindingInfo binding) {
079: bindings.put(binding.getName(), binding);
080: }
081:
082: public EndpointInfo getEndpoint(QName qn) {
083: return endpoints.get(qn);
084: }
085:
086: public void addEndpoint(EndpointInfo ep) {
087: endpoints.put(ep.getName(), ep);
088: }
089:
090: public Collection<EndpointInfo> getEndpoints() {
091: return Collections.unmodifiableCollection(endpoints.values());
092: }
093:
094: public Collection<BindingInfo> getBindings() {
095: return Collections.unmodifiableCollection(bindings.values());
096: }
097:
098: public Map<QName, MessageInfo> getMessages() {
099: if (messages == null) {
100: initMessagesMap();
101: }
102: return messages;
103: }
104:
105: public MessageInfo getMessage(QName qname) {
106: return getMessages().get(qname);
107: }
108:
109: private void initMessagesMap() {
110: messages = new ConcurrentHashMap<QName, MessageInfo>();
111: for (OperationInfo operation : getInterface().getOperations()) {
112: if (operation.getInput() != null) {
113: messages.put(operation.getInput().getName(), operation
114: .getInput());
115: }
116: if (operation.getOutput() != null) {
117: messages.put(operation.getOutput().getName(), operation
118: .getOutput());
119: }
120: }
121: }
122:
123: public void setMessages(Map<QName, MessageInfo> msgs) {
124: messages = msgs;
125: }
126:
127: public void refresh() {
128: initMessagesMap();
129: }
130:
131: public void addSchema(SchemaInfo schemaInfo) {
132: schemas.add(schemaInfo);
133: }
134:
135: public SchemaInfo getSchema(String namespaceURI) {
136: for (SchemaInfo s : schemas) {
137: if (namespaceURI != null) {
138: if (namespaceURI.equals(s.getNamespaceURI())) {
139: return s;
140: }
141: } else if (s.getNamespaceURI() == null) {
142: return s;
143: }
144: }
145: return null;
146: }
147:
148: public Collection<SchemaInfo> getSchemas() {
149: return Collections.unmodifiableCollection(schemas);
150: }
151:
152: public void setXmlSchemaCollection(XmlSchemaCollection col) {
153: this .xmlSchemaCollection = col;
154: }
155:
156: public XmlSchemaCollection getXmlSchemaCollection() {
157: return xmlSchemaCollection;
158: }
159: }
|