Example usage for javax.xml.stream XMLStreamWriter writeCharacters

List of usage examples for javax.xml.stream XMLStreamWriter writeCharacters

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeCharacters.

Prototype

public void writeCharacters(String text) throws XMLStreamException;

Source Link

Document

Write text to the output

Usage

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

private void addColumn(Parameter columnParam, Extension exn, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("column");
    Parameter columnNameParam = columnParam.getSubParameter("name");
    if (columnNameParam != null) {
        String columnName = columnNameParam.valueAsString();
        if (columnName.trim().length() == 0) {
            throw new RuntimeException(exn.getUniqueId() + " requires a column name parameter value");
        }//  ww w .j a  v  a  2 s . c  om
        xmlStreamWriter.writeAttribute("name", columnName);
    }
    Parameter lengthParam = columnParam.getSubParameter("length");
    if (lengthParam != null) {
        int length = lengthParam.valueAsNumber().intValue();
        xmlStreamWriter.writeAttribute("length", String.valueOf(length));
    }
    Parameter columnDefinitionParam = columnParam.getSubParameter("column-definition");
    if (columnDefinitionParam != null) {
        String columnDefintion = columnDefinitionParam.valueAsString();
        if (columnDefintion.trim().length() == 0) {
            throw new RuntimeException(
                    exn.getUniqueId() + " requires a column column-definition parameter value");
        }
        xmlStreamWriter.writeAttribute("column-definition", columnDefintion);
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected void addEmbeddables(PluginDescriptor pd, String ormId, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_EMBEDDABLE);
    if (exnPt != null && getDescriptor().getId().equals(exnPt.getParentPluginId())) {
        ParameterDefinition targetPluginIdParamDef = exnPt.getParameterDefinition("target-plugin-id");
        if (targetPluginIdParamDef == null || targetPluginIdParamDef.getDefaultValue() == null
                || targetPluginIdParamDef.getDefaultValue().trim().length() == 0) {
            throw new RuntimeException(exnPt.getUniqueId()
                    + " must defined a parameter-def called target-plugin-id with a default value");
        }//from  w ww .  ja v a2s . co  m
        if (pd.getId().equals(targetPluginIdParamDef.getDefaultValue())) {
            for (Extension exn : exnPt.getConnectedExtensions()) {
                if (containsORMId(ormId, exn.getParameters("ormId"))) {
                    xmlStreamWriter.writeStartElement("embeddable");
                    String clazz = exn.getParameter("class").valueAsString();
                    if (clazz == null || clazz.trim().length() == 0) {
                        throw new RuntimeException(exn.getUniqueId() + " requires a class parameter value");
                    }
                    xmlStreamWriter.writeAttribute("class", clazz);
                    xmlStreamWriter.writeCharacters("\n");
                    addAttributes(exn, xmlStreamWriter);
                    xmlStreamWriter.writeEndElement();
                    xmlStreamWriter.writeCharacters("\n");
                }
            }
        }
    }
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected void addEnterpriseBeansChildren(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "addEnterpriseBeansChildren");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();/*w  w w.  ja  va2s . c  o  m*/
    xmlStreamWriter.writeCharacters("\n");
    addEnterpriseBeansCreate(false, xmlStreamWriter);
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected void addEnterpriseBeansCreate(boolean hasEnterpriseBeans, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("name", "createEnterpriseBeans");
    xmlStreamWriter.writeCharacters("\n");
    if (hasEnterpriseBeans) {
        logger.debug("Enterprise beans tag will be created");
        xmlStreamWriter.writeStartElement("enterprise-beans");
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeStartElement("xsl:call-template");
        xmlStreamWriter.writeAttribute("name", "createEnterpriseBeansChildren");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.writeCharacters("\n");
    } else {/*from www  . ja v a 2  s.  c o  m*/
        logger.debug("No enterprise beans tag will be created");
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected void addEntities(PluginDescriptor pd, String ormId, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_ENTITY);
    if (exnPt != null && getDescriptor().getId().equals(exnPt.getParentPluginId())) {
        ParameterDefinition targetPluginIdParamDef = exnPt.getParameterDefinition("target-plugin-id");
        if (targetPluginIdParamDef == null || targetPluginIdParamDef.getDefaultValue() == null
                || targetPluginIdParamDef.getDefaultValue().trim().length() == 0) {
            throw new RuntimeException(exnPt.getUniqueId()
                    + " must defined a parameter-def called target-plugin-id with a default value");
        }/* w  w w. ja va2  s.  com*/
        if (pd.getId().equals(targetPluginIdParamDef.getDefaultValue())) {
            for (Extension exn : exnPt.getConnectedExtensions()) {
                if (containsORMId(ormId, exn.getParameters("ormId"))) {
                    xmlStreamWriter.writeStartElement("entity");
                    String clazz = exn.getParameter("class").valueAsString();
                    if (clazz == null || clazz.trim().length() == 0) {
                        throw new RuntimeException(exn.getUniqueId() + " requires a class parameter value");
                    }
                    xmlStreamWriter.writeAttribute("class", clazz);
                    xmlStreamWriter.writeCharacters("\n");
                    Parameter tableParam = exn.getParameter("table");
                    if (tableParam != null) {
                        xmlStreamWriter.writeStartElement("table");
                        if (tableParam.getSubParameter("name") != null) {
                            String tableName = tableParam.getSubParameter("name").valueAsString();
                            if (tableName.trim().length() > 0) {
                                xmlStreamWriter.writeAttribute("name", tableName);
                            }
                        }
                        if (tableParam.getSubParameter("schema") != null) {
                            String schema = tableParam.getSubParameter("schema").valueAsString();
                            if (schema.trim().length() > 0) {
                                xmlStreamWriter.writeAttribute("schema", schema);
                            }
                        }
                        addUniqueConstraints(tableParam.getSubParameters("unique-constraint"), xmlStreamWriter);
                        xmlStreamWriter.writeEndElement();
                        xmlStreamWriter.writeCharacters("\n");
                    }
                    Parameter discriminatorColumnParam = exn.getParameter("discriminator-column");
                    if (discriminatorColumnParam != null) {
                        xmlStreamWriter.writeStartElement("discriminator-column");
                        if (discriminatorColumnParam.getSubParameter("name") != null) {
                            String discriminatorColumnName = discriminatorColumnParam.getSubParameter("name")
                                    .valueAsString();
                            if (discriminatorColumnName.trim().length() == 0) {
                                throw new RuntimeException(exn.getUniqueId()
                                        + " requires a discriminator-column name parameter value");
                            }
                            xmlStreamWriter.writeAttribute("name", discriminatorColumnName);
                        }
                        Parameter lengthParam = discriminatorColumnParam.getSubParameter("length");
                        if (lengthParam != null) {
                            int length = lengthParam.valueAsNumber().intValue();
                            xmlStreamWriter.writeAttribute("length", String.valueOf(length));
                        }
                        xmlStreamWriter.writeEndElement();
                        xmlStreamWriter.writeCharacters("\n");
                    }
                    addAttributes(exn, xmlStreamWriter);
                    xmlStreamWriter.writeEndElement();
                    xmlStreamWriter.writeCharacters("\n");
                }
            }
        }
    }
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

private void addJoinColumn(Parameter joinColumnParam, Extension exn, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("join-column");
    if (joinColumnParam.getSubParameter("name") != null) {
        String joinColumnName = joinColumnParam.getSubParameter("name").valueAsString();
        if (joinColumnName.trim().length() == 0) {
            throw new RuntimeException(exn.getUniqueId() + " requires a join-column name parameter value");
        }/*from  ww  w  .jav  a  2 s  .c  om*/
        xmlStreamWriter.writeAttribute("name", joinColumnName);
    }
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected void addMainTemplate(XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("xsl:template");
    xmlStreamWriter.writeAttribute("match", "/ | * | @* | text() | comment()");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:copy");
    xmlStreamWriter.writeAttribute("select", ".");
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeStartElement("xsl:apply-templates");
    xmlStreamWriter.writeAttribute("select", "* | @* | text() | comment()");
    xmlStreamWriter.writeEndElement();//from  www.  java 2s .  c o  m
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
    xmlStreamWriter.writeEndElement();
    xmlStreamWriter.writeCharacters("\n");
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected void addMappedSuperclasses(PluginDescriptor pd, String ormId, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_MAPPED_SUPERCLASS);
    if (exnPt != null && getDescriptor().getId().equals(exnPt.getParentPluginId())) {
        ParameterDefinition targetPluginIdParamDef = exnPt.getParameterDefinition("target-plugin-id");
        if (targetPluginIdParamDef == null || targetPluginIdParamDef.getDefaultValue() == null
                || targetPluginIdParamDef.getDefaultValue().trim().length() == 0) {
            throw new RuntimeException(exnPt.getUniqueId()
                    + " must defined a parameter-def called target-plugin-id with a default value");
        }/* ww w .  j av  a2s . co  m*/
        if (pd.getId().equals(targetPluginIdParamDef.getDefaultValue())) {
            for (Extension exn : exnPt.getConnectedExtensions()) {
                if (containsORMId(ormId, exn.getParameters("ormId"))) {
                    xmlStreamWriter.writeStartElement("mapped-superclass");
                    String clazz = exn.getParameter("class").valueAsString();
                    if (clazz == null || clazz.trim().length() == 0) {
                        throw new RuntimeException(exn.getUniqueId() + " requires a class parameter value");
                    }
                    xmlStreamWriter.writeAttribute("class", clazz);
                    xmlStreamWriter.writeCharacters("\n");
                    addAttributes(exn, xmlStreamWriter);
                    xmlStreamWriter.writeEndElement();
                    xmlStreamWriter.writeCharacters("\n");
                }
            }
        }
    }
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected void addPersistenceUnit(PluginDescriptor pd, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_PERSISTENCE_UNIT);
    if (exnPt != null && getDescriptor().getId().equals(exnPt.getParentPluginId())) {
        ParameterDefinition targetPluginIdParamDef = exnPt.getParameterDefinition("target-plugin-id");
        if (targetPluginIdParamDef == null || targetPluginIdParamDef.getDefaultValue() == null
                || targetPluginIdParamDef.getDefaultValue().trim().length() == 0) {
            throw new RuntimeException(exnPt.getUniqueId()
                    + " must defined a parameter-def called target-plugin-id with a default value");
        }//  ww w.  j  av  a 2  s .c  o  m
        if (pd.getId().equals(targetPluginIdParamDef.getDefaultValue())) {
            ExtensionPoint ormExnPt = getMyExtensionPoint(EXNPT_ORM);
            Extension ormExn = ormExnPt.getConnectedExtensions().iterator().next();
            String ormId = ormExn.getParameter("ormId").valueAsString();
            if (ormId == null || ormId.length() == 0) {
                throw new RuntimeException(ormExnPt.getUniqueId() + "@ormId must have a value");
            }
            String name = ormExn.getParameter("name").valueAsString();
            if (name == null || name.length() == 0) {
                throw new RuntimeException(ormExnPt.getUniqueId() + "@name must have a value");
            }
            String transactionType = ormExn.getParameter("transaction-type").valueAsString();
            if (transactionType == null || transactionType.length() == 0) {
                throw new RuntimeException(ormExnPt.getUniqueId() + "@transaction-type must have a value");
            }
            String jtaDataSource = ormExn.getParameter("jta-data-source").valueAsString();
            if (jtaDataSource == null || jtaDataSource.length() == 0) {
                throw new RuntimeException(ormExnPt.getUniqueId() + "@jta-data-source must have a value");
            }
            for (Extension exn : exnPt.getConnectedExtensions()) {

                if (containsORMId(ormId, exn.getParameters("ormId"))) {
                    xmlStreamWriter.writeStartElement("persistence-unit");
                    if (name.trim().length() == 0) {
                        throw new RuntimeException(exn.getUniqueId() + " requires a name parameter value");
                    }
                    xmlStreamWriter.writeAttribute("name", name);
                    if (transactionType.trim().length() == 0) {
                        throw new RuntimeException(
                                exn.getUniqueId() + " requires a transaction-type parameter value");
                    }
                    xmlStreamWriter.writeAttribute("transaction-type", transactionType);
                    xmlStreamWriter.writeCharacters("\n");
                    Parameter providerParam = exn.getParameter("provider");
                    if (providerParam != null) {
                        xmlStreamWriter.writeStartElement("provider");
                        String provider = providerParam.valueAsString();
                        if (provider.trim().length() == 0) {
                            throw new RuntimeException(
                                    exn.getUniqueId() + " requires a provider parameter value");
                        }
                        xmlStreamWriter.writeCharacters(provider);
                        xmlStreamWriter.writeEndElement();
                        xmlStreamWriter.writeCharacters("\n");
                    }
                    xmlStreamWriter.writeStartElement("jta-data-source");
                    if (jtaDataSource.trim().length() == 0) {
                        throw new RuntimeException(
                                exn.getUniqueId() + " requires a jta-data-source parameter value");
                    }
                    xmlStreamWriter.writeCharacters(jtaDataSource);
                    xmlStreamWriter.writeEndElement();
                    xmlStreamWriter.writeCharacters("\n");
                    xmlStreamWriter.writeStartElement("mapping-file");
                    String mappingFile = exn.getParameter("mapping-file").valueAsString();
                    if (mappingFile.trim().length() == 0) {
                        throw new RuntimeException(
                                exn.getUniqueId() + " requires a mapping-file parameter value");
                    }
                    xmlStreamWriter.writeCharacters(
                            "META-INF/" + exn.getDeclaringPluginDescriptor().getId() + "-" + mappingFile);
                    xmlStreamWriter.writeEndElement();
                    xmlStreamWriter.writeCharacters("\n");
                    List<Parameter> propertyParams = new ArrayList<Parameter>();
                    propertyParams.addAll(exn.getParameters("property"));
                    if (!propertyParams.isEmpty()) {
                        xmlStreamWriter.writeStartElement("properties");
                        for (Parameter propertyParameter : propertyParams) {
                            xmlStreamWriter.writeStartElement("property");
                            String propertyName = propertyParameter.getSubParameter("name").valueAsString();
                            if (mappingFile.trim().length() == 0) {
                                throw new RuntimeException(
                                        exn.getUniqueId() + " requires a property name parameter value");
                            }
                            xmlStreamWriter.writeAttribute("name", propertyName);
                            String propertyValue = propertyParameter.getSubParameter("value").valueAsString();
                            if (mappingFile.trim().length() == 0) {
                                throw new RuntimeException(
                                        exn.getUniqueId() + " requires a property value parameter value");
                            }
                            xmlStreamWriter.writeAttribute("value", propertyValue);
                            xmlStreamWriter.writeEndElement();
                            xmlStreamWriter.writeCharacters("\n");
                        }
                        xmlStreamWriter.writeEndElement();
                        xmlStreamWriter.writeCharacters("\n");
                    }
                    xmlStreamWriter.writeEndElement();
                    xmlStreamWriter.writeCharacters("\n");
                }
            }
        }
    }
}

From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java

protected void addPersistenceUnitMetadata(PluginDescriptor pd, String ormId, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    ExtensionPoint exnPt = pd.getExtensionPoint(EXNPT_PERSISTENCE_UNIT_METADATA);
    if (exnPt != null && getDescriptor().getId().equals(exnPt.getParentPluginId())) {
        ParameterDefinition targetPluginIdParamDef = exnPt.getParameterDefinition("target-plugin-id");
        if (targetPluginIdParamDef == null || targetPluginIdParamDef.getDefaultValue() == null
                || targetPluginIdParamDef.getDefaultValue().trim().length() == 0) {
            throw new RuntimeException(exnPt.getUniqueId()
                    + " must defined a parameter-def called target-plugin-id with a default value");
        }/*from w ww.  jav  a 2s . c  o m*/
        if (pd.getId().equals(targetPluginIdParamDef.getDefaultValue())) {
            for (Extension exn : exnPt.getConnectedExtensions()) {
                if (containsORMId(ormId, exn.getParameters("ormId"))) {
                    xmlStreamWriter.writeStartElement("persistence-unit-metadata");
                    xmlStreamWriter.writeCharacters("\n");
                    Parameter persistenceUnitDefaultsParam = exn.getParameter("persistence-unit-defaults");
                    if (persistenceUnitDefaultsParam != null) {
                        xmlStreamWriter.writeStartElement("persistence-unit-defaults");
                        xmlStreamWriter.writeCharacters("\n");
                        if (persistenceUnitDefaultsParam.getSubParameter("schema") != null) {
                            String schema = persistenceUnitDefaultsParam.getSubParameter("schema")
                                    .valueAsString();
                            if (schema.trim().length() == 0) {
                                throw new RuntimeException(
                                        exn.getUniqueId() + " requires a schema parameter value");
                            }
                            xmlStreamWriter.writeStartElement("schema");
                            xmlStreamWriter.writeCharacters(schema);
                            xmlStreamWriter.writeEndElement();
                            xmlStreamWriter.writeCharacters("\n");
                        }
                        xmlStreamWriter.writeEndElement();
                        xmlStreamWriter.writeCharacters("\n");
                    }
                    xmlStreamWriter.writeEndElement();
                    xmlStreamWriter.writeCharacters("\n");
                }
            }
        }
    }
}