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.ws.rm;
019:
020: import java.io.OutputStream;
021: import java.text.MessageFormat;
022:
023: import org.apache.cxf.endpoint.Endpoint;
024: import org.apache.cxf.io.WriteOnCloseOutputStream;
025: import org.apache.cxf.message.Message;
026: import org.apache.cxf.ws.addressing.AddressingConstants;
027: import org.apache.cxf.ws.addressing.AddressingConstantsImpl;
028: import org.apache.cxf.ws.addressing.VersionTransformer;
029:
030: public final class RMUtils {
031:
032: private static final org.apache.cxf.ws.addressing.v200408.ObjectFactory WSA_FACTORY;
033: private static final org.apache.cxf.ws.rm.ObjectFactory WSRM_FACTORY;
034: private static final AddressingConstants WSA_CONSTANTS;
035:
036: static {
037: WSA_FACTORY = new org.apache.cxf.ws.addressing.v200408.ObjectFactory();
038: WSRM_FACTORY = new org.apache.cxf.ws.rm.ObjectFactory();
039: WSA_CONSTANTS = new AddressingConstantsImpl();
040: }
041:
042: protected RMUtils() {
043: }
044:
045: public static org.apache.cxf.ws.addressing.v200408.ObjectFactory getWSAFactory() {
046: return WSA_FACTORY;
047: }
048:
049: public static org.apache.cxf.ws.rm.ObjectFactory getWSRMFactory() {
050: return WSRM_FACTORY;
051: }
052:
053: public static AddressingConstants getAddressingConstants() {
054: return WSA_CONSTANTS;
055: }
056:
057: public static org.apache.cxf.ws.addressing.EndpointReferenceType createAnonymousReference() {
058: return createReference(org.apache.cxf.ws.addressing.Names.WSA_ANONYMOUS_ADDRESS);
059: }
060:
061: public static org.apache.cxf.ws.addressing.v200408.EndpointReferenceType createAnonymousReference2004() {
062: return VersionTransformer.convert(createAnonymousReference());
063: }
064:
065: public static org.apache.cxf.ws.addressing.EndpointReferenceType createNoneReference() {
066: return createReference(org.apache.cxf.ws.addressing.Names.WSA_NONE_ADDRESS);
067: }
068:
069: public static org.apache.cxf.ws.addressing.v200408.EndpointReferenceType createNoneReference2004() {
070: return VersionTransformer.convert(createNoneReference());
071: }
072:
073: public static org.apache.cxf.ws.addressing.EndpointReferenceType createReference(
074: String address) {
075: org.apache.cxf.ws.addressing.ObjectFactory factory = new org.apache.cxf.ws.addressing.ObjectFactory();
076: org.apache.cxf.ws.addressing.EndpointReferenceType epr = factory
077: .createEndpointReferenceType();
078: org.apache.cxf.ws.addressing.AttributedURIType uri = factory
079: .createAttributedURIType();
080: uri.setValue(address);
081: epr.setAddress(uri);
082: return epr;
083: }
084:
085: public static org.apache.cxf.ws.addressing.v200408.EndpointReferenceType createReference2004(
086: String address) {
087: org.apache.cxf.ws.addressing.v200408.ObjectFactory factory = new org.apache.cxf.ws.addressing.v200408.ObjectFactory();
088: org.apache.cxf.ws.addressing.v200408.EndpointReferenceType epr = factory
089: .createEndpointReferenceType();
090: org.apache.cxf.ws.addressing.v200408.AttributedURI uri = factory
091: .createAttributedURI();
092: uri.setValue(address);
093: epr.setAddress(uri);
094: return epr;
095: }
096:
097: public static String getEndpointIdentifier(Endpoint endpoint) {
098: return MessageFormat.format("{0}.{1}", new Object[] {
099: endpoint.getEndpointInfo().getService().getName(),
100: endpoint.getEndpointInfo().getName() });
101: }
102:
103: public static WriteOnCloseOutputStream createCachedStream(
104: Message message, OutputStream os) {
105: // We need to ensure that we have an output stream which won't start writing the
106: // message until we have a chance to send a createsequence
107: if (!(os instanceof WriteOnCloseOutputStream)) {
108: WriteOnCloseOutputStream cached = new WriteOnCloseOutputStream(
109: os);
110: message.setContent(OutputStream.class, cached);
111: os = cached;
112: }
113: return (WriteOnCloseOutputStream) os;
114: }
115: }
|