001 /** 002 * 003 * Copyright 2004 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 package org.codehaus.activesoap.soap; 019 020 import org.codehaus.activesoap.SoapFault; 021 022 import javax.xml.namespace.QName; 023 import javax.xml.stream.XMLStreamException; 024 import javax.xml.stream.XMLStreamWriter; 025 026 /** 027 * Represents the SOAP 1.2 version 028 * 029 * @version $Revision: 1.1 $ 030 */ 031 public class Soap11 implements SoapVersion { 032 private static Soap11 instance = new Soap11(); 033 034 private double version = 1.2; 035 private String namespace = "http://schemas.xmlsoap.org/soap/envelope/"; 036 private String prefix = "env"; 037 private String noneRole = namespace + "/role/none"; 038 private String ultimateReceiverRole = namespace + "/role/ultimateReceiver"; 039 private String nextRole = namespace + "/role/next"; 040 private String soapEncodingStyle = "http://www.w3.org/2003/05/soap-encoding"; 041 042 private QName envelope = new QName(namespace, "Envelope", prefix); 043 private QName header = new QName(namespace, "Header", prefix); 044 private QName body = new QName(namespace, "Body", prefix); 045 046 public static Soap11 getInstance() { 047 return instance; 048 } 049 050 public void writeStartElement(XMLStreamWriter out, String localName) throws XMLStreamException { 051 out.writeStartElement(prefix, localName, namespace); 052 } 053 054 public void writeFault(XMLStreamWriter out, SoapFault fault) throws XMLStreamException { 055 writeStartElement(out, "Fault"); 056 057 String code = fault.getCode(); 058 if (code != null) { 059 writeStartElement(out, "faultcode"); 060 out.writeCharacters(prefix + ":" + code); 061 out.writeEndElement(); 062 } 063 String reason = fault.getReason(); 064 if (reason == null) { 065 reason = fault.getCause().toString(); 066 } 067 writeStartElement(out, "faultstring"); 068 out.writeCharacters(reason); 069 out.writeEndElement(); 070 071 writeStartElement(out, "detail"); 072 out.writeEndElement(); 073 074 String role = fault.getRole(); 075 if (role != null) { 076 writeStartElement(out, "faultactor"); 077 out.writeCharacters(role); 078 out.writeEndElement(); 079 } 080 } 081 082 public double getVersion() { 083 return version; 084 } 085 086 public String getNamespace() { 087 return namespace; 088 } 089 090 public String getPrefix() { 091 return prefix; 092 } 093 094 public QName getEnvelope() { 095 return envelope; 096 } 097 098 public QName getHeader() { 099 return header; 100 } 101 102 public QName getBody() { 103 return body; 104 } 105 106 107 public String getSoapEncodingStyle() { 108 return soapEncodingStyle; 109 } 110 111 // Role URIs 112 //------------------------------------------------------------------------- 113 public String getNoneRole() { 114 return noneRole; 115 } 116 117 public String getUltimateReceiverRole() { 118 return ultimateReceiverRole; 119 } 120 121 public String getNextRole() { 122 return nextRole; 123 } 124 }