javax.xml.stream.XMLStreamWriter#writeEmptyElement ( )源码实例Demo

下面列出了javax.xml.stream.XMLStreamWriter#writeEmptyElement ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hop   文件: XmlFormatter.java
public void writeTo( XMLStreamWriter wr, boolean empty ) throws XMLStreamException {
  if ( empty ) {
    if ( namespace != null ) {
      wr.writeEmptyElement( prefix, localName, namespace );
    } else {
      wr.writeEmptyElement( localName );
    }
  } else {
    if ( namespace != null ) {
      wr.writeStartElement( prefix, localName, namespace );
    } else {
      wr.writeStartElement( localName );
    }
  }
  for ( AttrBuffer a : attrBuffer ) {
    a.writeTo( wr );
  }
}
 
源代码2 项目: iaf   文件: SchemaUtils.java
public static void
		mergeRootXsdsGroupedByNamespaceToSchemasWithIncludes(
		Map<String, Set<XSD>> rootXsdsGroupedByNamespace,
		XMLStreamWriter xmlStreamWriter)
		throws IOException, XMLStreamException {
	// As the root XSD's are written as includes there's no need to change
	// the imports and includes in the root XSD's.
	for (String namespace: rootXsdsGroupedByNamespace.keySet()) {
		xmlStreamWriter.writeStartElement(XSD, "schema");
		xmlStreamWriter.writeAttribute("targetNamespace", namespace);
		for (XSD xsd : rootXsdsGroupedByNamespace.get(namespace)) {
			xmlStreamWriter.writeEmptyElement(XSD, "include");
			xmlStreamWriter.writeAttribute("schemaLocation",
					xsd.getResourceTarget());
		}
		xmlStreamWriter.writeEndElement();
	}
}
 
源代码3 项目: iaf   文件: Wsdl.java
protected void writeSoapHeader(XMLStreamWriter w, String root, QName headerElement, boolean isHeaderOptional) throws XMLStreamException, IOException {
    if (headerElement != null) {
        w.writeEmptyElement(wsdlSoapNamespace, "header");
        w.writeAttribute("part", "Part_" + headerElement.getLocalPart());
        w.writeAttribute("use", "literal");
        w.writeAttribute("message", getTargetNamespacePrefix() + ":" + "Message_" + root + (isHeaderOptional ? "_" + headerElement.getLocalPart() : ""));
    }
}
 
源代码4 项目: packagedrone   文件: XmlProfileDataHandler.java
private void dumpEntry ( final XMLStreamWriter xsw, final DurationEntry entry, final int level ) throws XMLStreamException
{
    indent ( xsw, level );

    final boolean empty = entry.getEntries ().isEmpty ();

    if ( empty )
    {
        xsw.writeEmptyElement ( "operation" );
    }
    else
    {
        xsw.writeStartElement ( "operation" );
    }

    // write attributes

    xsw.writeAttribute ( "name", entry.getOperation () );
    xsw.writeAttribute ( "duration", "" + entry.getDuration ().toMillis () );

    if ( !empty )
    {
        xsw.writeCharacters ( "\n" );
        dumpEntries ( xsw, entry.getEntries (), level + 1 );

        // end element

        indent ( xsw, level );
        xsw.writeEndElement ();
    }

    xsw.writeCharacters ( "\n" );
}
 
源代码5 项目: wildfly-core   文件: AttributeMarshallers.java
@Override
public void marshallSingleElement(AttributeDefinition attribute, ModelNode property, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {
    ObjectMapAttributeDefinition map = ((ObjectMapAttributeDefinition) attribute);
    AttributeDefinition[] valueTypes = map.getValueType().getValueTypes();
    writer.writeEmptyElement(elementName);
    Property p = property.asProperty();
    writer.writeAttribute(keyAttributeName, p.getName());
    for (AttributeDefinition valueType : valueTypes) {
        valueType.getMarshaller().marshall(valueType, p.getValue(), false, writer);
    }
}
 
private void appendNavigationPropertyBindings(final XMLStreamWriter writer, final EdmBindingTarget bindingTarget)
    throws XMLStreamException {
  if (bindingTarget.getNavigationPropertyBindings() != null) {
    for (EdmNavigationPropertyBinding binding : bindingTarget.getNavigationPropertyBindings()) {
      writer.writeEmptyElement(XML_NAVIGATION_PROPERTY_BINDING);
      writer.writeAttribute(XML_PATH, binding.getPath());
      writer.writeAttribute(XML_TARGET, binding.getTarget());
    }
  }
}
 
源代码7 项目: phoebus   文件: XMLWriteTest.java
/** Create example XML content */
private void writeExampleContent(final XMLStreamWriter writer) throws XMLStreamException
{
    writer.writeStartDocument(XMLUtil.ENCODING, "1.0");
    {   // Blocks mimic nesting of elements
        writer.writeStartElement("display");
        {
            writer.writeStartElement("widget");
            writer.writeAttribute("type", "whatever");
            {
                writer.writeStartElement("x");
                writer.writeCharacters("42");
                writer.writeEndElement();

                writer.writeStartElement("y");
                writer.writeCharacters("73");
                writer.writeEndElement();

                writer.writeEmptyElement("align");
                writer.writeAttribute("side", "left");

                writer.writeStartElement("text");
                writer.writeCharacters("Hello, Dolly!");
                writer.writeEndElement();

                writer.writeEmptyElement("option");
                writer.writeAttribute("wrap", "true");
            }
            writer.writeEndElement();
        }
        writer.writeEndElement();
    }
    writer.writeEndDocument();
    writer.flush();
    writer.close();
}
 
源代码8 项目: iaf   文件: Wsdl.java
protected void httpService(XMLStreamWriter w, String servlet, String namePrefix) throws XMLStreamException {
	w.writeStartElement(WSDL_NAMESPACE, "service");
    w.writeAttribute("name", "Service_" + WsdlUtils.getNCName(getName())); {
        w.writeStartElement(WSDL_NAMESPACE, "port");
        w.writeAttribute("name", namePrefix + "Port_" + WsdlUtils.getNCName(getName()));
        w.writeAttribute("binding", getTargetNamespacePrefix() + ":" + namePrefix + "Binding_" + WsdlUtils.getNCName(getName())); {
            w.writeEmptyElement(wsdlSoapNamespace, "address");
            w.writeAttribute("location", getLocation(servlet));
        }
        w.writeEndElement();
    }
    w.writeEndElement();
}
 
源代码9 项目: nifi-registry   文件: HtmlExtensionDocWriter.java
protected void writeValidValues(final XMLStreamWriter xmlStreamWriter, final Property property) throws XMLStreamException {
        if (property.getAllowableValues() != null && property.getAllowableValues().size() > 0) {
            xmlStreamWriter.writeStartElement("ul");
            for (AllowableValue value : property.getAllowableValues()) {
                xmlStreamWriter.writeStartElement("li");
                xmlStreamWriter.writeCharacters(value.getDisplayName());

                if (!StringUtils.isBlank(value.getDescription())) {
                    writeValidValueDescription(xmlStreamWriter, value.getDescription());
                }
                xmlStreamWriter.writeEndElement();
            }
            xmlStreamWriter.writeEndElement();
        } else if (property.getControllerServiceDefinition() != null) {
            final ControllerServiceDefinition serviceDefinition = property.getControllerServiceDefinition();
            final String controllerServiceClass = getSimpleName(serviceDefinition.getClassName());

            final String group = serviceDefinition.getGroupId() == null ? "unknown" : serviceDefinition.getGroupId();
            final String artifact = serviceDefinition.getArtifactId() == null ? "unknown" : serviceDefinition.getArtifactId();
            final String version = serviceDefinition.getVersion() == null ? "unknown" : serviceDefinition.getVersion();

            writeSimpleElement(xmlStreamWriter, "strong", "Controller Service API: ");
            xmlStreamWriter.writeEmptyElement("br");
            xmlStreamWriter.writeCharacters(controllerServiceClass);

            writeValidValueDescription(xmlStreamWriter, group + "-" + artifact + "-" + version);

//            xmlStreamWriter.writeEmptyElement("br");
//            xmlStreamWriter.writeCharacters(group);
//            xmlStreamWriter.writeEmptyElement("br");
//            xmlStreamWriter.writeCharacters(artifact);
//            xmlStreamWriter.writeEmptyElement("br");
//            xmlStreamWriter.writeCharacters(version);
        }
    }
 
源代码10 项目: wildfly-core   文件: JvmAttributes.java
@Override
public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {
    if (resourceModel.hasDefined(attribute.getName())) {
        List<ModelNode> list = resourceModel.get(attribute.getName()).asList();
        if (list.size() > 0) {
            writer.writeStartElement(attribute.getName());
            for (ModelNode child : list) {
                writer.writeEmptyElement(Element.OPTION.getLocalName());
                writer.writeAttribute(ModelDescriptionConstants.VALUE, child.asString());
            }
            writer.writeEndElement();
        }
    }
}
 
源代码11 项目: jeka   文件: ModulesXmlGenerator.java
private void _generate() throws IOException, XMLStreamException, FactoryConfigurationError {

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos, ENCODING);
        writer.writeStartDocument(ENCODING, "1.0");
        writer.writeCharacters("\n");
        writer.writeStartElement("project");
        writer.writeCharacters("\n" + T1);
        writer.writeStartElement("component");
        writer.writeAttribute("name", "ProjectModuleManager");
        writer.writeCharacters("\n" + T2);
        writer.writeStartElement("modules");
        writer.writeCharacters("\n");
        for (final Path iml : imlFiles) {
            final Path relPath = projectDir.relativize(iml);
            JkLog.info("Iml file detected : " + relPath);
            final String path = path(relPath);
            writer.writeCharacters(T3);
            writer.writeEmptyElement("module");
            writer.writeAttribute("fileurl", "file://" + path);
            writer.writeAttribute("filepath", path);
            writer.writeCharacters("\n");
        }
        writer.writeCharacters(T2);
        writer.writeEndElement();
        writer.writeCharacters("\n" + T1);
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        writer.close();
        JkUtilsPath.deleteIfExists(outputFile);
        JkUtilsPath.createDirectories(outputFile.getParent());
        Files.write(outputFile, baos.toByteArray());
    }
 
源代码12 项目: wildfly-core   文件: PropertyAttributeMarshaller.java
@Override
public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {
    resourceModel = resourceModel.get(attribute.getName());
    if (resourceModel.isDefined()) {
        writer.writeStartElement(attribute.getName());
        for (Property property : resourceModel.asPropertyList()) {
            writer.writeEmptyElement(Element.PROPERTY.getLocalName());
            writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
            writer.writeAttribute(Attribute.VALUE.getLocalName(), property.getValue().asString());
        }
        writer.writeEndElement();
    }
}
 
源代码13 项目: ironjacamar   文件: DsParser.java
/**
 * Store timeout
 * @param t The timeout
 * @param writer The writer
 * @exception Exception Thrown if an error occurs
 */
protected void storeTimeout(Timeout t, XMLStreamWriter writer) throws Exception
{
   writer.writeStartElement(XML.ELEMENT_TIMEOUT);

   if (t.getBlockingTimeoutMillis() != null)
   {
      writer.writeStartElement(XML.ELEMENT_BLOCKING_TIMEOUT_MILLIS);
      writer.writeCharacters(t.getValue(XML.ELEMENT_BLOCKING_TIMEOUT_MILLIS,
                                        t.getBlockingTimeoutMillis().toString()));
      writer.writeEndElement();
   }

   if (t.getIdleTimeoutMinutes() != null)
   {
      writer.writeStartElement(XML.ELEMENT_IDLE_TIMEOUT_MINUTES);
      writer.writeCharacters(t.getValue(XML.ELEMENT_IDLE_TIMEOUT_MINUTES, t.getIdleTimeoutMinutes().toString()));
      writer.writeEndElement();
   }

   if (t.isSetTxQueryTimeout() != null && Boolean.TRUE.equals(t.isSetTxQueryTimeout()))
   {
      writer.writeEmptyElement(XML.ELEMENT_SET_TX_QUERY_TIMEOUT);
   }

   if (t.getQueryTimeout() != null)
   {
      writer.writeStartElement(XML.ELEMENT_QUERY_TIMEOUT);
      writer.writeCharacters(t.getValue(XML.ELEMENT_QUERY_TIMEOUT, t.getQueryTimeout().toString()));
      writer.writeEndElement();
   }

   if (t.getUseTryLock() != null)
   {
      writer.writeStartElement(XML.ELEMENT_USE_TRY_LOCK);
      writer.writeCharacters(t.getValue(XML.ELEMENT_USE_TRY_LOCK, t.getUseTryLock().toString()));
      writer.writeEndElement();
   }

   if (t.getAllocationRetry() != null)
   {
      writer.writeStartElement(XML.ELEMENT_ALLOCATION_RETRY);
      writer.writeCharacters(t.getValue(XML.ELEMENT_ALLOCATION_RETRY, t.getAllocationRetry().toString()));
      writer.writeEndElement();
   }

   if (t.getAllocationRetryWaitMillis() != null)
   {
      writer.writeStartElement(XML.ELEMENT_ALLOCATION_RETRY_WAIT_MILLIS);
      writer.writeCharacters(t.getValue(XML.ELEMENT_ALLOCATION_RETRY_WAIT_MILLIS,
                                        t.getAllocationRetryWaitMillis().toString()));
      writer.writeEndElement();
   }

   if (t.getXaResourceTimeout() != null)
   {
      writer.writeStartElement(XML.ELEMENT_XA_RESOURCE_TIMEOUT);
      writer.writeCharacters(t.getValue(XML.ELEMENT_XA_RESOURCE_TIMEOUT, t.getXaResourceTimeout().toString()));
      writer.writeEndElement();
   }

   writer.writeEndElement();
}
 
源代码14 项目: iaf   文件: Wsdl.java
protected void jmsService(XMLStreamWriter w, JmsListener listener, String namePrefix) throws XMLStreamException, NamingException {
    w.writeStartElement(WSDL_NAMESPACE, "service");
    w.writeAttribute("name", "Service_" + WsdlUtils.getNCName(getName())); {
        if (!esbSoap) {
            // Per example of https://docs.jboss.org/author/display/JBWS/SOAP+over+JMS
            w.writeStartElement(SOAP_JMS_NAMESPACE, "jndiConnectionFactoryName");
            w.writeCharacters(listener.getQueueConnectionFactoryName());
        }
        w.writeStartElement(WSDL_NAMESPACE, "port");
        w.writeAttribute("name", namePrefix + "Port_" + WsdlUtils.getNCName(getName()));
        w.writeAttribute("binding", getTargetNamespacePrefix() + ":" + namePrefix + "Binding_" + WsdlUtils.getNCName(getName())); {
            w.writeEmptyElement(wsdlSoapNamespace, "address");
            String destinationName = listener.getDestinationName();
            if (destinationName != null) {
                w.writeAttribute("location", getLocation(destinationName));
            }
            if (esbSoap) {
                writeEsbSoapJndiContext(w, listener);
                w.writeStartElement(ESB_SOAP_JMS_NAMESPACE, "connectionFactory"); {
                    w.writeCharacters("externalJndiName-for-"
                            + listener.getQueueConnectionFactoryName()
                            + "-on-"
                            + AppConstants.getInstance().getResolvedProperty("dtap.stage"));
                    w.writeEndElement();
                }
                w.writeStartElement(ESB_SOAP_JMS_NAMESPACE, "targetAddress"); {
                    w.writeAttribute("destination",
                            listener.getDestinationType().toLowerCase());
                    String queueName = listener.getPhysicalDestinationShortName();
                    if (queueName == null) {
                        queueName = "queueName-for-"
                                + listener.getDestinationName() + "-on-"
                                + AppConstants.getInstance().getResolvedProperty("dtap.stage");
                    }
                    w.writeCharacters(queueName);
                    w.writeEndElement();
                }
            }
        }
        w.writeEndElement();
    }
    w.writeEndElement();
}
 
源代码15 项目: hawkular-agent   文件: Modules.java
void writeModuleXml(Writer out, AddModuleRequest addModuleRequest) throws XMLStreamException {

        XMLStreamWriter writer = new PrettyWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(out));
        writer.writeStartDocument();
        writer.writeStartElement(Name.module.toString());
        writer.writeDefaultNamespace(Name.module_ns.toString());

        writer.writeAttribute(Name.name.toString(), addModuleRequest.getModuleName());

        final String slot = addModuleRequest.getSlot();
        if (slot != null) {
            writer.writeAttribute(Name.slot.toString(), slot);
        }

        final Map<String, String> properties = addModuleRequest.getProperties();
        if (properties != null && !properties.isEmpty()) {
            writer.writeStartElement(Name.properties.toString());
            for (Map.Entry<String, String> entry : properties.entrySet()) {
                writer.writeEmptyElement(Name.property.toString());
                writer.writeAttribute(Name.name.toString(), entry.getKey());
                writer.writeAttribute(Name.value.toString(), entry.getValue());
            }
            writer.writeEndElement();
        }

        final String mainClass = addModuleRequest.getMainClass();
        if (mainClass != null) {
            writer.writeEmptyElement(Name.main_class.toString());
            writer.writeAttribute(Name.value.toString(), mainClass);
        }

        final Set<ModuleResource> resources = addModuleRequest.getResources();
        if (resources != null && !resources.isEmpty()) {
            writer.writeStartElement(Name.resources.toString());
            for (ModuleResource resource : resources) {
                writer.writeEmptyElement(Name.resource_root.toString());
                writer.writeAttribute(Name.path.toString(), resource.getFileName());
            }
            writer.writeEndElement();
        }

        final Set<String> dependencies = addModuleRequest.getDependencies();
        if (dependencies != null && !dependencies.isEmpty()) {
            writer.writeStartElement(Name.dependencies.toString());
            for (String dep : dependencies) {
                writer.writeEmptyElement(Name.module.toString());
                writer.writeAttribute(Name.name.toString(), dep);
            }
            writer.writeEndElement();
        }

        writer.writeEndElement();
        writer.writeEndDocument();
    }
 
源代码16 项目: karaf-boot   文件: JpaProcessor.java
public void process(Writer writer, Map<PersistentUnit, List<? extends AnnotationMirror>> units) throws Exception {
    Set<String> puNames = new HashSet<String>();
    XMLOutputFactory xof =  XMLOutputFactory.newInstance();
    XMLStreamWriter w = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(writer));
    w.setDefaultNamespace("http://java.sun.com/xml/ns/persistence");
    w.writeStartDocument();
    w.writeStartElement("persistence");
    w.writeAttribute("verson", "2.0");
    
    //w.println("<persistence version=\"2.0\" xmlns=\"http://java.sun.com/xml/ns/persistence\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd\">");
    for (PersistentUnit pu : units.keySet()) {
        if (pu.name() == null || pu.name().isEmpty()) {
            throw new IOException("Missing persistent unit name");
        }
        if (!puNames.add(pu.name())) {
            throw new IOException("Duplicate persistent unit name: " + pu.name());
        }
        w.writeStartElement("persistence-unit");
        w.writeAttribute("name", pu.name());
        w.writeAttribute("transaction-type", pu.transactionType().toString());
        writeElement(w, "description", pu.description());
        String providerName = getProvider(pu);
        writeElement(w, "provider", providerName);
        writeElement(w, "jta-data-source", pu.jtaDataSource());
        writeElement(w, "non-jta-data-source", pu.nonJtaDataSource());
        Map<String, String> props = new HashMap<>();
        addProperties(pu, props);
        addAnnProperties(units.get(pu), props);
        if (props.size() > 0) {
            w.writeStartElement("properties");
            for (String key : props.keySet()) {
                w.writeEmptyElement("property");
                w.writeAttribute("name", key);
                w.writeAttribute("value", props.get(key));
            }
            w.writeEndElement();
        }
        w.writeEndElement();
    }
    w.writeEndElement();
    w.writeEndDocument();
    w.flush();
    w.close();
}
 
源代码17 项目: owltools   文件: PseudoRdfXmlWriter.java
private void writeRelation(XMLStreamWriter writer, String rel, String targetId) throws XMLStreamException {
	writer.writeEmptyElement(GO_NAMESPACE_URI, rel);
	writer.writeAttribute(RDF_NAMESPACE_URI, "resource", "http://www.geneontology.org/go#" + targetId);
}
 
源代码18 项目: steady   文件: SecureConversationToken.java
public void serialize(XMLStreamWriter writer) throws XMLStreamException {

        String localname = getRealName().getLocalPart();
        String namespaceURI = getRealName().getNamespaceURI();
        String prefix;

        String writerPrefix = writer.getPrefix(namespaceURI);

        if (writerPrefix == null) {
            prefix = getRealName().getPrefix();
            writer.setPrefix(prefix, namespaceURI);
        } else {
            prefix = writerPrefix;
        }

        // <sp:SecureConversationToken>
        writer.writeStartElement(prefix, localname, namespaceURI);

        if (writerPrefix == null) {
            // xmlns:sp=".."
            writer.writeNamespace(prefix, namespaceURI);
        }

        String inclusion;

        inclusion = constants.getAttributeValueFromInclusion(getInclusion());

        if (inclusion != null) {
            writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
        }

        if (issuerEpr != null) {
            // <sp:Issuer>
            writer.writeStartElement(prefix, SPConstants.ISSUER, namespaceURI);

            StaxUtils.copy(issuerEpr, writer);

            writer.writeEndElement();
        }

        if (isDerivedKeys() || isRequireExternalUriRef() || isSc10SecurityContextToken()
            || isSc13SecurityContextToken() || bootstrapPolicy != null) {

            String wspNamespaceURI = SPConstants.POLICY.getNamespaceURI();

            String wspPrefix;

            String wspWriterPrefix = writer.getPrefix(wspNamespaceURI);

            if (wspWriterPrefix == null) {
                wspPrefix = SPConstants.POLICY.getPrefix();
                writer.setPrefix(wspPrefix, wspNamespaceURI);

            } else {
                wspPrefix = wspWriterPrefix;
            }

            // <wsp:Policy>
            writer.writeStartElement(wspPrefix, SPConstants.POLICY.getLocalPart(), wspNamespaceURI);

            if (wspWriterPrefix == null) {
                // xmlns:wsp=".."
                writer.writeNamespace(wspPrefix, wspNamespaceURI);
            }

            if (isDerivedKeys()) {
                // <sp:RequireDerivedKeys />
                writer.writeEmptyElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
            }

            if (isRequireExternalUriRef()) {
                // <sp:RequireExternalUriReference />
                writer.writeEmptyElement(prefix, SPConstants.REQUIRE_EXTERNAL_URI_REFERENCE, namespaceURI);
            }

            if (isSc10SecurityContextToken()) {
                // <sp:SC10SecurityContextToken />
                writer.writeEmptyElement(prefix, SPConstants.SC10_SECURITY_CONTEXT_TOKEN, namespaceURI);
            }
            
            if (isSc13SecurityContextToken()) {
                // <sp:SC13SecurityContextToken />
                writer.writeEmptyElement(prefix, SPConstants.SC13_SECURITY_CONTEXT_TOKEN, namespaceURI);
            }

            if (bootstrapPolicy != null) {
                // <sp:BootstrapPolicy ..>
                writer.writeStartElement(prefix, SPConstants.BOOTSTRAP_POLICY, namespaceURI);
                bootstrapPolicy.serialize(writer);
                writer.writeEndElement();
            }

            // </wsp:Policy>
            writer.writeEndElement();
        }

        // </sp:SecureConversationToken>
        writer.writeEndElement();
    }
 
源代码19 项目: steady   文件: SymmetricBinding.java
public void serialize(XMLStreamWriter writer) throws XMLStreamException {

        String localname = getRealName().getLocalPart();
        String namespaceURI = getRealName().getNamespaceURI();

        String prefix;
        String writerPrefix = writer.getPrefix(namespaceURI);

        if (writerPrefix == null) {
            prefix = getRealName().getPrefix();
            writer.setPrefix(prefix, namespaceURI);
        } else {
            prefix = writerPrefix;
        }

        // <sp:SymmetricBinding>
        writer.writeStartElement(prefix, localname, namespaceURI);

        // xmlns:sp=".."
        writer.writeNamespace(prefix, namespaceURI);

        String policyLocalName = SPConstants.POLICY.getLocalPart();
        String policyNamespaceURI = SPConstants.POLICY.getNamespaceURI();

        String wspPrefix;

        String wspWriterPrefix = writer.getPrefix(policyNamespaceURI);
        if (wspWriterPrefix == null) {
            wspPrefix = SPConstants.POLICY.getPrefix();
            writer.setPrefix(wspPrefix, policyNamespaceURI);

        } else {
            wspPrefix = wspWriterPrefix;
        }
        // <wsp:Policy>
        writer.writeStartElement(wspPrefix, policyLocalName, policyNamespaceURI);

        if (encryptionToken != null) {
            encryptionToken.serialize(writer);

        } else if (protectionToken != null) {
            protectionToken.serialize(writer);

        } else {
            throw new RuntimeException("Either EncryptionToken or ProtectionToken must be set");
        }

        AlgorithmSuite algorithmSuite = getAlgorithmSuite();

        if (algorithmSuite == null) {
            throw new RuntimeException("AlgorithmSuite must be set");
        }
        // <sp:AlgorithmSuite />
        algorithmSuite.serialize(writer);

        Layout layout = getLayout();
        if (layout != null) {
            // <sp:Layout />
            layout.serialize(writer);
        }

        if (isIncludeTimestamp()) {
            // <sp:IncludeTimestamp />
            writer.writeStartElement(prefix, SPConstants.INCLUDE_TIMESTAMP, namespaceURI);
            writer.writeEndElement();
        }

        if (SPConstants.ProtectionOrder.EncryptBeforeSigning == getProtectionOrder()) {
            // <sp:EncryptBeforeSigning />
            writer.writeStartElement(prefix, SPConstants.ENCRYPT_BEFORE_SIGNING, namespaceURI);
            writer.writeEndElement();
        }

        if (isSignatureProtection()) {
            // <sp:EncryptSignature />
            writer.writeStartElement(prefix, SPConstants.ENCRYPT_SIGNATURE, namespaceURI);
            writer.writeEndElement();
        }

        if (isEntireHeadersAndBodySignatures()) {
            writer.writeEmptyElement(prefix, SPConstants.ONLY_SIGN_ENTIRE_HEADERS_AND_BODY, namespaceURI);
        }
        // </wsp:Policy>
        writer.writeEndElement();

        // </sp:SymmetricBinding>
        writer.writeEndElement();

    }
 
源代码20 项目: steady   文件: IssuedToken.java
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localname = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix;
    String writerPrefix = writer.getPrefix(namespaceURI);

    if (writerPrefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);

    } else {
        prefix = writerPrefix;
    }

    // <sp:IssuedToken>
    writer.writeStartElement(prefix, localname, namespaceURI);

    if (writerPrefix == null) {
        writer.writeNamespace(prefix, namespaceURI);
    }

    String inclusion;

    inclusion = constants.getAttributeValueFromInclusion(getInclusion());

    if (inclusion != null) {
        writer.writeAttribute(prefix, namespaceURI, SPConstants.ATTR_INCLUDE_TOKEN, inclusion);
    }

    if (issuerEpr != null) {
        JAXBElement<EndpointReferenceType> elem 
            = new JAXBElement<EndpointReferenceType>(new QName(namespaceURI, SPConstants.ISSUER), 
                EndpointReferenceType.class, issuerEpr);
        try {
            ContextUtils.getJAXBContext().createMarshaller().marshal(elem, writer);
        } catch (JAXBException e) {
            //ignore
        }
    }

    if (rstTemplate != null) {
        // <sp:RequestSecurityTokenTemplate>
        StaxUtils.copy(rstTemplate, writer);
    }

    String policyLocalName = SPConstants.POLICY.getLocalPart();
    String policyNamespaceURI = SPConstants.POLICY.getNamespaceURI();

    String wspPrefix;

    String wspWriterPrefix = writer.getPrefix(policyNamespaceURI);

    if (wspWriterPrefix == null) {
        wspPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(wspPrefix, policyNamespaceURI);
    } else {
        wspPrefix = wspWriterPrefix;
    }

    if (isRequireExternalReference() || isRequireInternalReference() || this.isDerivedKeys()) {

        // <wsp:Policy>
        writer.writeStartElement(wspPrefix, policyLocalName, policyNamespaceURI);

        if (wspWriterPrefix == null) {
            // xmlns:wsp=".."
            writer.writeNamespace(wspPrefix, policyNamespaceURI);
        }

        if (isRequireExternalReference()) {
            // <sp:RequireExternalReference />
            writer.writeEmptyElement(prefix, SPConstants.REQUIRE_EXTERNAL_REFERENCE, namespaceURI);
        }

        if (isRequireInternalReference()) {
            // <sp:RequireInternalReference />
            writer.writeEmptyElement(prefix, SPConstants.REQUIRE_INTERNAL_REFERENCE, namespaceURI);
        }

        if (this.isDerivedKeys()) {
            // <sp:RequireDerivedKeys />
            writer.writeEmptyElement(prefix, SPConstants.REQUIRE_DERIVED_KEYS, namespaceURI);
        }

        // <wsp:Policy>
        writer.writeEndElement();
    }

    // </sp:IssuedToken>
    writer.writeEndElement();
}