use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class PolicyModelMarshallerTest method testMarshal_Collection_Object.
/**
* Test of marshal method, of class PolicyModelMarshaller.
*/
public void testMarshal_Collection_Object() throws PolicyException {
Collection<PolicySourceModel> models = new LinkedList<PolicySourceModel>();
PolicySourceModel model = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_2);
PolicySourceModel model2 = PolicySourceModel.createPolicySourceModel(NamespaceVersion.v1_5);
models.add(model);
models.add(model2);
Document document = builder.newDocument();
TypedXmlWriter storage = TXW.create(new QName("policies"), TypedXmlWriter.class, new DomSerializer(document));
PolicyModelMarshaller instance = PolicyModelMarshaller.getXmlMarshaller(false);
instance.marshal(models, storage);
storage.commit();
Element element = document.getDocumentElement();
Node policyElement = element.getFirstChild();
assertEquals(policyElement.getLocalName(), "Policy");
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenerator method generateBindingOperation.
protected void generateBindingOperation(JavaMethodImpl method, Binding binding) {
BindingOperationType operation = binding.operation().name(method.getOperationName());
extension.addBindingOperationExtension(operation, method);
String targetNamespace = model.getTargetNamespace();
QName requestMessage = new QName(targetNamespace, method.getOperationName());
List<ParameterImpl> bodyParams = new ArrayList<>();
List<ParameterImpl> headerParams = new ArrayList<>();
splitParameters(bodyParams, headerParams, method.getRequestParameters());
SOAPBinding soapBinding = method.getBinding();
operation.soapOperation().soapAction(soapBinding.getSOAPAction());
// input
TypedXmlWriter input = operation.input();
extension.addBindingOperationInputExtension(input, method);
BodyType body = input._element(Body.class);
boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
if (soapBinding.getUse() == Use.LITERAL) {
body.use(LITERAL);
if (headerParams.size() > 0) {
if (bodyParams.size() > 0) {
ParameterImpl param = bodyParams.iterator().next();
if (isRpc) {
StringBuilder parts = new StringBuilder();
int i = 0;
for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
if (i++ > 0)
parts.append(' ');
parts.append(parameter.getPartName());
}
body.parts(parts.toString());
} else {
body.parts(param.getPartName());
}
} else {
body.parts("");
}
generateSOAPHeaders(input, headerParams, requestMessage);
}
if (isRpc) {
body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
}
} else {
// TODO localize this
throw new WebServiceException("encoded use is not supported");
}
if (method.getMEP() != MEP.ONE_WAY) {
// output
bodyParams.clear();
headerParams.clear();
splitParameters(bodyParams, headerParams, method.getResponseParameters());
TypedXmlWriter output = operation.output();
extension.addBindingOperationOutputExtension(output, method);
body = output._element(Body.class);
body.use(LITERAL);
if (headerParams.size() > 0) {
StringBuilder parts = new StringBuilder();
if (bodyParams.size() > 0) {
ParameterImpl param = bodyParams.iterator().hasNext() ? bodyParams.iterator().next() : null;
if (param != null) {
if (isRpc) {
int i = 0;
for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
if (i++ > 0) {
parts.append(" ");
}
parts.append(parameter.getPartName());
}
} else {
parts = new StringBuilder(param.getPartName());
}
}
}
body.parts(parts.toString());
QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
generateSOAPHeaders(output, headerParams, responseMessage);
}
if (isRpc) {
body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
}
}
for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
Fault fault = operation.fault().name(exception.getMessageName());
extension.addBindingOperationFaultExtension(fault, method, exception);
SOAPFault soapFault = fault._element(SOAPFault.class).name(exception.getMessageName());
soapFault.use(LITERAL);
}
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class TXWContentHandler method startElement.
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
TypedXmlWriter txw = stack.peek()._element(uri, localName, TypedXmlWriter.class);
stack.push(txw);
if (atts != null) {
for (int i = 0; i < atts.getLength(); i++) {
String auri = atts.getURI(i);
if ("http://www.w3.org/2000/xmlns/".equals(auri)) {
if ("xmlns".equals(atts.getLocalName(i)))
txw._namespace(atts.getValue(i), "");
else
txw._namespace(atts.getValue(i), atts.getLocalName(i));
} else {
if ("schemaLocation".equals(atts.getLocalName(i)) && "".equals(atts.getValue(i)))
continue;
txw._attribute(auri, atts.getLocalName(i), atts.getValue(i));
}
}
}
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class W3CAddressingMetadataWSDLGeneratorExtension method start.
@Override
public void start(WSDLGenExtnContext ctxt) {
TypedXmlWriter root = ctxt.getRoot();
root._namespace(W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME, W3CAddressingMetadataConstants.WSAM_PREFIX_NAME);
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class W3CAddressingWSDLGeneratorExtension method start.
@Override
public void start(WSDLGenExtnContext ctxt) {
WSBinding binding = ctxt.getBinding();
TypedXmlWriter root = ctxt.getRoot();
enabled = binding.isFeatureEnabled(AddressingFeature.class);
if (!enabled)
return;
AddressingFeature ftr = binding.getFeature(AddressingFeature.class);
required = ftr.isRequired();
root._namespace(AddressingVersion.W3C.wsdlNsUri, AddressingVersion.W3C.getWsdlPrefix());
}
Aggregations