use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLGeneratorExtension method writePolicyOrReferenceIt.
/**
* Adds a PolicyReference element that points to the policy of the element,
* if the policy does not have any id or name. Writes policy inside the element otherwise.
*
* @param subject
* PolicySubject to be referenced or marshalled
* @param writer
* A TXW on to which we shall add the PolicyReference
*/
private void writePolicyOrReferenceIt(final PolicySubject subject, final TypedXmlWriter writer) {
final Policy policy;
try {
policy = subject.getEffectivePolicy(merger);
} catch (PolicyException e) {
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e));
}
if (policy != null) {
if (null == policy.getIdOrName()) {
final PolicyModelGenerator generator = ModelGenerator.getGenerator();
try {
final PolicySourceModel policyInfoset = generator.translate(policy);
marshaller.marshal(policyInfoset, writer);
} catch (PolicyException pe) {
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1002_UNABLE_TO_MARSHALL_POLICY_OR_POLICY_REFERENCE(), pe));
}
} else {
final TypedXmlWriter policyReference = writer._element(policy.getNamespaceVersion().asQName(XmlToken.PolicyReference), TypedXmlWriter.class);
policyReference._attribute(XmlToken.Uri.toString(), '#' + policy.getIdOrName());
}
}
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLGeneratorExtension method start.
@Override
public void start(final WSDLGenExtnContext context) {
LOGGER.entering();
try {
this.seiModel = context.getModel();
final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators();
final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length];
for (int i = 0; i < policyMapConfigurators.length; i++) {
extenders[i] = PolicyMapExtender.createPolicyMapExtender();
}
// Read policy config file
policyMap = PolicyResolverFactory.create().resolve(new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders));
if (policyMap == null) {
LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP());
policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders));
}
final WSBinding binding = context.getBinding();
try {
final Collection<PolicySubject> policySubjects = new LinkedList<>();
for (int i = 0; i < policyMapConfigurators.length; i++) {
policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding));
extenders[i].disconnect();
}
PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName());
} catch (PolicyException e) {
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e));
}
final TypedXmlWriter root = context.getRoot();
root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix());
root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix());
root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX);
} finally {
LOGGER.exiting();
}
}
use of com.sun.xml.txw2.TypedXmlWriter in project metro-jax-ws by eclipse-ee4j.
the class XmlPolicyModelMarshaller method marshal.
/**
* Marshal a policy onto the given XMLStreamWriter.
*
* @param model A policy source model.
* @param writer An XML stream writer.
* @throws PolicyException If marshalling failed.
*/
private void marshal(final PolicySourceModel model, final XMLStreamWriter writer) throws PolicyException {
final StaxSerializer serializer = new StaxSerializer(writer);
final TypedXmlWriter policy = TXW.create(model.getNamespaceVersion().asQName(XmlToken.Policy), TypedXmlWriter.class, serializer);
marshalDefaultPrefixes(model, policy);
marshalPolicyAttributes(model, policy);
marshal(model.getNamespaceVersion(), model.getRootNode(), policy);
policy.commit();
serializer.flush();
}
use of com.sun.xml.txw2.TypedXmlWriter in project jaxb-ri by eclipse-ee4j.
the class TXW method create.
/**
* Creates a new {@link TypedXmlWriter} to write a new instance of a document.
*
* @param <T> an instance of {@link TypedXmlWriter}
* @param rootElement
* The {@link TypedXmlWriter} interface that declares the content model of the root element.
* This interface must have {@link XmlElement} annotation on it to designate the tag name
* of the root element.
* @param out
* The target of the writing.
* @return
* always return non-null {@link TypedXmlWriter} that can be used
* to write the contents of the root element.
*/
public static <T extends TypedXmlWriter> T create(Class<T> rootElement, XmlSerializer out) {
if (out instanceof TXWSerializer) {
TXWSerializer txws = (TXWSerializer) out;
return txws.txw._element(rootElement);
}
Document doc = new Document(out);
QName n = getTagName(rootElement);
return new ContainerElement(doc, null, n.getNamespaceURI(), n.getLocalPart())._cast(rootElement);
}
use of com.sun.xml.txw2.TypedXmlWriter in project jaxb-ri by eclipse-ee4j.
the class ContainerElement method addElement.
/**
* Writes a new element.
*/
@SuppressWarnings("unchecked")
private Object addElement(XmlElement e, Method method, Object[] args) {
Class<?> rt = method.getReturnType();
// the last precedence: default name
String nsUri = "##default";
String localName = method.getName();
if (e != null) {
// then the annotation on this method
if (e.value().length() != 0)
localName = e.value();
nsUri = e.ns();
}
if (nsUri.equals("##default")) {
// look for the annotation on the declaring class
Class<?> c = method.getDeclaringClass();
XmlElement ce = c.getAnnotation(XmlElement.class);
if (ce != null) {
nsUri = ce.ns();
}
if (nsUri.equals("##default"))
// then default to the XmlNamespace
nsUri = getNamespace(c.getPackage());
}
if (rt == Void.TYPE) {
// leaf element with just a value
boolean isCDATA = method.getAnnotation(XmlCDATA.class) != null;
StartTag st = new StartTag(document, nsUri, localName);
addChild(st);
for (Object arg : args) {
Text text;
if (isCDATA)
text = new Cdata(document, st, arg);
else
text = new Pcdata(document, st, arg);
addChild(text);
}
addChild(new EndTag());
return null;
}
if (TypedXmlWriter.class.isAssignableFrom(rt)) {
// sub writer
return _element(nsUri, localName, (Class<? extends TypedXmlWriter>) rt);
}
throw new IllegalSignatureException("Illegal return type: " + rt);
}
Aggregations