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.tools.validator.internal;
019:
020: import java.util.ArrayList;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import javax.wsdl.Binding;
025: import javax.wsdl.BindingOperation;
026: import javax.wsdl.Definition;
027: import javax.wsdl.extensions.ExtensibilityElement;
028: import javax.wsdl.extensions.mime.MIMEContent;
029: import javax.wsdl.extensions.mime.MIMEMultipartRelated;
030: import javax.wsdl.extensions.mime.MIMEPart;
031:
032: import org.apache.cxf.tools.util.SOAPBindingUtil;
033:
034: public class MIMEBindingValidator extends AbstractDefinitionValidator {
035:
036: public MIMEBindingValidator(Definition def) {
037: super (def);
038: }
039:
040: public boolean isValid() {
041: Iterator itBinding = def.getBindings().keySet().iterator();
042: while (itBinding.hasNext()) {
043: Binding binding = (Binding) def.getBindings().get(
044: itBinding.next());
045: Iterator itOperation = binding.getBindingOperations()
046: .iterator();
047: while (itOperation.hasNext()) {
048: BindingOperation bindingOperation = (BindingOperation) itOperation
049: .next();
050: Iterator itInputExt = bindingOperation
051: .getBindingInput().getExtensibilityElements()
052: .iterator();
053: while (itInputExt.hasNext()) {
054: ExtensibilityElement extElement = (ExtensibilityElement) itInputExt
055: .next();
056: if (extElement instanceof MIMEMultipartRelated) {
057: Iterator itMimeParts = ((MIMEMultipartRelated) extElement)
058: .getMIMEParts().iterator();
059: if (!doValidate(itMimeParts, bindingOperation
060: .getName())) {
061: return false;
062: }
063: }
064: }
065: }
066: }
067: return true;
068: }
069:
070: private boolean doValidate(Iterator mimeParts, String operationName) {
071: boolean gotRootPart = false;
072: while (mimeParts.hasNext()) {
073: MIMEPart mPart = (MIMEPart) mimeParts.next();
074: List<MIMEContent> mimeContents = new ArrayList<MIMEContent>();
075: Iterator extns = mPart.getExtensibilityElements()
076: .iterator();
077: while (extns.hasNext()) {
078: ExtensibilityElement extElement = (ExtensibilityElement) extns
079: .next();
080: if (SOAPBindingUtil.isSOAPBody(extElement)) {
081: if (gotRootPart) {
082: addErrorMessage("Operation("
083: + operationName
084: + "): There's more than one soap body mime part"
085: + " in its binding input");
086: return false;
087: }
088: gotRootPart = true;
089: } else if (extElement instanceof MIMEContent) {
090: mimeContents.add((MIMEContent) extElement);
091: }
092: }
093: if (!doValidateMimeContentPartNames(
094: mimeContents.iterator(), operationName)) {
095: return false;
096: }
097: }
098: if (!gotRootPart) {
099: addErrorMessage("Operation(" + operationName
100: + "): There's no soap body in mime part"
101: + " in its binding input");
102: return false;
103: }
104: return true;
105: }
106:
107: private boolean doValidateMimeContentPartNames(
108: Iterator mimeContents, String operationName) {
109: // validate mime:content(s) in the mime:part as per R2909
110: String partName = null;
111: while (mimeContents.hasNext()) {
112: MIMEContent mimeContent = (MIMEContent) mimeContents.next();
113: String mimeContnetPart = mimeContent.getPart();
114: if (mimeContnetPart == null) {
115: addErrorMessage("Operation("
116: + operationName
117: + "): Must provide part attribute value for meme:content elements");
118: return false;
119: } else {
120: if (partName == null) {
121: partName = mimeContnetPart;
122: } else {
123: if (!partName.equals(mimeContnetPart)) {
124: addErrorMessage("Operation("
125: + operationName
126: + "): Part attribute value for meme:content "
127: + "elements are different");
128: return false;
129: }
130: }
131: }
132: }
133: return true;
134: }
135: }
|