List of usage examples for javax.xml.stream XMLStreamWriter writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException;
From source file:org.tolven.assembler.ejbmodule.EJBModuleAssembler.java
private void addAttributes(Extension extension, XMLStreamWriter xmlStreamWriter) throws XMLStreamException { Parameter attributesParam = extension.getParameter("attributes"); if (attributesParam != null) { xmlStreamWriter.writeStartElement("attributes"); xmlStreamWriter.writeCharacters("\n"); for (Parameter idParam : attributesParam.getSubParameters("id")) { xmlStreamWriter.writeStartElement("id"); String idName = idParam.getSubParameter("name").valueAsString(); if (idName.trim().length() == 0) { throw new RuntimeException(extension.getUniqueId() + " requires a id name parameter value"); }/*from w ww . j a va 2 s. com*/ xmlStreamWriter.writeAttribute("name", idName); xmlStreamWriter.writeCharacters("\n"); Parameter columnParam = idParam.getSubParameter("column"); if (columnParam != null) { addColumn(columnParam, extension, xmlStreamWriter); } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } for (Parameter basicParam : attributesParam.getSubParameters("basic")) { xmlStreamWriter.writeStartElement("basic"); String basicName = basicParam.getSubParameter("name").valueAsString(); if (basicName == null || basicName.trim().length() == 0) { throw new RuntimeException(extension.getUniqueId() + " requires a name parameter value"); } xmlStreamWriter.writeAttribute("name", basicName); xmlStreamWriter.writeCharacters("\n"); Parameter columnParameter = basicParam.getSubParameter("column"); if (columnParameter != null) { addColumn(columnParameter, extension, xmlStreamWriter); } Parameter lobParam = basicParam.getSubParameter("lob"); if (lobParam != null) { xmlStreamWriter.writeStartElement("lob"); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } Parameter temporalParam = basicParam.getSubParameter("temporal"); if (temporalParam != null) { xmlStreamWriter.writeStartElement("temporal"); String temporal = temporalParam.valueAsString(); if (temporal.trim().length() == 0) { throw new RuntimeException( extension.getUniqueId() + " requires a temporal parameter value"); } xmlStreamWriter.writeCharacters(temporal); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } Parameter enumeratedParam = basicParam.getSubParameter("enumerated"); if (enumeratedParam != null) { xmlStreamWriter.writeStartElement("enumerated"); String enumerated = enumeratedParam.valueAsString(); if (enumerated.trim().length() == 0) { throw new RuntimeException( extension.getUniqueId() + " requires a enumerated parameter value"); } xmlStreamWriter.writeCharacters(enumerated); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } for (Parameter idParam : attributesParam.getSubParameters("version")) { xmlStreamWriter.writeStartElement("version"); String versionName = idParam.getSubParameter("name").valueAsString(); if (versionName.trim().length() == 0) { throw new RuntimeException( extension.getUniqueId() + " requires a version name parameter value"); } xmlStreamWriter.writeAttribute("name", versionName); xmlStreamWriter.writeCharacters("\n"); Parameter columnParamter = idParam.getSubParameter("column"); if (columnParamter != null) { addColumn(columnParamter, extension, xmlStreamWriter); } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } for (Parameter idParam : attributesParam.getSubParameters("many-to-one")) { xmlStreamWriter.writeStartElement("many-to-one"); String manyToOneName = idParam.getSubParameter("name").valueAsString(); if (manyToOneName.trim().length() == 0) { throw new RuntimeException( extension.getUniqueId() + " requires a many-to-one name parameter value"); } xmlStreamWriter.writeAttribute("name", manyToOneName); xmlStreamWriter.writeCharacters("\n"); Parameter joinColumnParamter = idParam.getSubParameter("join-column"); if (joinColumnParamter != null) { addJoinColumn(joinColumnParamter, extension, xmlStreamWriter); } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } for (Parameter embeddedParam : attributesParam.getSubParameters("embedded")) { xmlStreamWriter.writeStartElement("embedded"); String embeddedName = embeddedParam.getSubParameter("name").valueAsString(); if (embeddedName.trim().length() == 0) { throw new RuntimeException( extension.getUniqueId() + " requires a embedded name parameter value"); } xmlStreamWriter.writeAttribute("name", embeddedName); xmlStreamWriter.writeCharacters("\n"); for (Parameter attributeOverrideParam : embeddedParam.getSubParameters("attribute-override")) { xmlStreamWriter.writeStartElement("attribute-override"); String attributeOverrideName = attributeOverrideParam.getSubParameter("name").valueAsString(); if (attributeOverrideName == null || attributeOverrideName.trim().length() == 0) { throw new RuntimeException( extension.getUniqueId() + " requires an attribute-override name parameter value"); } xmlStreamWriter.writeAttribute("name", attributeOverrideName); xmlStreamWriter.writeCharacters("\n"); Parameter attributeOverrdieColumnParameter = attributeOverrideParam.getSubParameter("column"); addColumn(attributeOverrdieColumnParameter, extension, xmlStreamWriter); xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } xmlStreamWriter.writeEndElement(); xmlStreamWriter.writeCharacters("\n"); } }
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"); }/*from w ww .j a v a2s . 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 ww w . j a v a2 s . c o 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();/*from w w w . ja v a 2 s . 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 {/* w w w. j a va 2s. 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 . j a v a 2 s. co m 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 . j a v a2s. 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();//www .ja v a 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"); }/*www .j av a2 s. c o 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"); }/*www.j a v a2s.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"); } } } } }