Example usage for org.w3c.dom Attr setValue

List of usage examples for org.w3c.dom Attr setValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr setValue.

Prototype

public void setValue(String value) throws DOMException;

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:io.personium.common.auth.token.TransCellAccessToken.java

/**
 * ?SAML????.//  ww w  .  j av a 2s  .c o m
 * @return SAML
 */
public String toSamlString() {

    /*
     * Creation of SAML2.0 Document
     * http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
     */

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder builder = null;
    try {
        builder = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        // ????????????
        throw new RuntimeException(e);
    }
    Document doc = builder.newDocument();
    Element assertion = doc.createElementNS(URN_OASIS_NAMES_TC_SAML_2_0_ASSERTION, "Assertion");
    doc.appendChild(assertion);
    assertion.setAttribute("ID", this.id);
    assertion.setAttribute("Version", "2.0");

    // Dummy Date
    DateTime dateTime = new DateTime(this.issuedAt);

    assertion.setAttribute("IssueInstant", dateTime.toString());

    // Issuer
    Element issuer = doc.createElement("Issuer");
    issuer.setTextContent(this.issuer);
    assertion.appendChild(issuer);

    // Subject
    Element subject = doc.createElement("Subject");
    Element nameId = doc.createElement("NameID");
    nameId.setTextContent(this.subject);
    Element subjectConfirmation = doc.createElement("SubjectConfirmation");
    subject.appendChild(nameId);
    subject.appendChild(subjectConfirmation);
    assertion.appendChild(subject);

    // Conditions
    Element conditions = doc.createElement("Conditions");
    Element audienceRestriction = doc.createElement("AudienceRestriction");
    for (String aud : new String[] { this.target, this.schema }) {
        Element audience = doc.createElement("Audience");
        audience.setTextContent(aud);
        audienceRestriction.appendChild(audience);
    }
    conditions.appendChild(audienceRestriction);
    assertion.appendChild(conditions);

    // AuthnStatement
    Element authnStmt = doc.createElement("AuthnStatement");
    authnStmt.setAttribute("AuthnInstant", dateTime.toString());
    Element authnCtxt = doc.createElement("AuthnContext");
    Element authnCtxtCr = doc.createElement("AuthnContextClassRef");
    authnCtxtCr.setTextContent("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
    authnCtxt.appendChild(authnCtxtCr);
    authnStmt.appendChild(authnCtxt);
    assertion.appendChild(authnStmt);

    // AttributeStatement
    Element attrStmt = doc.createElement("AttributeStatement");
    Element attribute = doc.createElement("Attribute");
    for (Role role : this.roleList) {
        Element attrValue = doc.createElement("AttributeValue");
        Attr attr = doc.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type");
        attr.setPrefix("xsi");
        attr.setValue("string");
        attrValue.setAttributeNodeNS(attr);
        attrValue.setTextContent(role.schemeCreateUrlForTranceCellToken(this.issuer));
        attribute.appendChild(attrValue);
    }
    attrStmt.appendChild(attribute);
    assertion.appendChild(attrStmt);

    // Normalization 
    doc.normalizeDocument();

    // Dsig??
    // Create a DOMSignContext and specify the RSA PrivateKey and
    // location of the resulting XMLSignature's parent element.
    DOMSignContext dsc = new DOMSignContext(privKey, doc.getDocumentElement());

    // Create the XMLSignature, but don't sign it yet.
    XMLSignature signature = xmlSignatureFactory.newXMLSignature(signedInfo, keyInfo);

    // Marshal, generate, and sign the enveloped signature.
    try {
        signature.sign(dsc);
        // ?
        return PersoniumCoreUtils.nodeToString(doc.getDocumentElement());
    } catch (MarshalException e1) {
        // DOM???????
        throw new RuntimeException(e1);
    } catch (XMLSignatureException e1) {
        // ??????????
        throw new RuntimeException(e1);
    }

    /*
     * ------------------------------------------------------------
     * http://tools.ietf.org/html/draft-ietf-oauth-saml2-bearer-10
     * ------------------------------------------------------------ 2.1. Using SAML Assertions as Authorization
     * Grants To use a SAML Bearer Assertion as an authorization grant, use the following parameter values and
     * encodings. The value of "grant_type" parameter MUST be "urn:ietf:params:oauth:grant-type:saml2-bearer" The
     * value of the "assertion" parameter MUST contain a single SAML 2.0 Assertion. The SAML Assertion XML data MUST
     * be encoded using base64url, where the encoding adheres to the definition in Section 5 of RFC4648 [RFC4648]
     * and where the padding bits are set to zero. To avoid the need for subsequent encoding steps (by "application/
     * x-www-form-urlencoded" [W3C.REC-html401-19991224], for example), the base64url encoded data SHOULD NOT be
     * line wrapped and pad characters ("=") SHOULD NOT be included.
     */
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

private void addDefaultValueAttribute(FieldMetadata field, Element columnElement) {
    // default value
    String defaultValueRule = field.getData(MetadataRepository.DEFAULT_VALUE_RULE);
    if (StringUtils.isNotBlank(defaultValueRule)) {
        Attr defaultValueAttr = document.createAttribute("default"); //$NON-NLS-1$
        defaultValueAttr.setValue(HibernateStorageUtils.convertedDefaultValue(dataSource.getDialectName(),
                defaultValueRule, "'"));
        columnElement.getAttributes().setNamedItem(defaultValueAttr);
    }/*from w w w.  j  a  v  a  2s. com*/
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

private Element newManyToManyElement(boolean enforceDataBaseIntegrity, ReferenceFieldMetadata referencedField) {
    // <many-to-many column="bar_id" class="Bar"/>
    Element manyToMany = document.createElement("many-to-many"); //$NON-NLS-1$
    // If data model authorizes fk integrity override, don't enforce database FK integrity.
    if (enforceDataBaseIntegrity) {
        // Ensure default settings for Hibernate are set (in case they change).
        Attr notFound = document.createAttribute("not-found"); //$NON-NLS-1$
        notFound.setValue("exception"); //$NON-NLS-1$
        manyToMany.getAttributes().setNamedItem(notFound);
        // foreign-key="..."
        String fkConstraintName = resolver.getFkConstraintName(referencedField);
        if (!fkConstraintName.isEmpty()) {
            Attr foreignKeyConstraintName = document.createAttribute("foreign-key"); //$NON-NLS-1$
            foreignKeyConstraintName.setValue(fkConstraintName);
            manyToMany.getAttributes().setNamedItem(foreignKeyConstraintName);
        }/*  w w  w . j  a v a 2 s  .  c o  m*/
    } else {
        // Disables all warning/errors from Hibernate.
        Attr integrity = document.createAttribute("unique"); //$NON-NLS-1$
        integrity.setValue("false"); //$NON-NLS-1$
        manyToMany.getAttributes().setNamedItem(integrity);

        Attr foreignKey = document.createAttribute("foreign-key"); //$NON-NLS-1$
        // Disables foreign key generation for DDL.
        foreignKey.setValue("none"); //$NON-NLS-1$
        manyToMany.getAttributes().setNamedItem(foreignKey);

        Attr notFound = document.createAttribute("not-found"); //$NON-NLS-1$
        notFound.setValue("ignore"); //$NON-NLS-1$
        manyToMany.getAttributes().setNamedItem(notFound);
    }
    Attr className = document.createAttribute("class"); //$NON-NLS-1$
    className.setValue(ClassCreator.getClassName(referencedField.getReferencedType().getName()));
    manyToMany.getAttributes().setNamedItem(className);
    isDoingColumns = true;
    this.parentElement = manyToMany;
    isColumnMandatory = referencedField.isMandatory() && generateConstrains;
    compositeKeyPrefix = referencedField.getName();
    {
        referencedField.getReferencedField().accept(this);
    }
    isDoingColumns = false;
    return manyToMany;
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

@Override
public Element visit(ReferenceFieldMetadata referenceField) {
    if (referenceField.isKey()) {
        throw new UnsupportedOperationException("FK field '" + referenceField.getName() //$NON-NLS-1$
                + "' cannot be key in type '" + referenceField.getDeclaringType().getName() + "'"); // Don't support FK as key  //$NON-NLS-1$ //$NON-NLS-2$
    } else {/*from w  w  w .j  a  v  a  2s . c  o  m*/
        boolean enforceDataBaseIntegrity = generateConstrains
                && (!referenceField.allowFKIntegrityOverride() && referenceField.isFKIntegrity());
        if (!referenceField.isMany()) {
            return newManyToOneElement(referenceField, enforceDataBaseIntegrity);
        } else {
            /*
            <list name="bars" table="foo_bar">
             <key column="foo_id"/>
             <many-to-many column="bar_id" class="Bar"/>
              </list>
             */
            Element propertyElement = document.createElement("list"); //$NON-NLS-1$
            Attr name = document.createAttribute("name"); //$NON-NLS-1$
            name.setValue(referenceField.getName());
            propertyElement.getAttributes().setNamedItem(name);
            Attr lazy = document.createAttribute("lazy"); //$NON-NLS-1$
            lazy.setValue("extra"); //$NON-NLS-1$
            propertyElement.getAttributes().setNamedItem(lazy);
            // fetch="select"
            Attr joinAttribute = document.createAttribute("fetch"); //$NON-NLS-1$
            joinAttribute.setValue("select"); // Keep it "select" (Hibernate tends to duplicate results when using "fetch") //$NON-NLS-1$
            propertyElement.getAttributes().setNamedItem(joinAttribute);
            // cascade="true"
            if (Boolean.parseBoolean(referenceField.<String>getData(SQL_DELETE_CASCADE))) {
                Attr cascade = document.createAttribute("cascade"); //$NON-NLS-1$
                cascade.setValue("lock, save-update, delete"); //$NON-NLS-1$
                propertyElement.getAttributes().setNamedItem(cascade);
            }
            Attr tableName = document.createAttribute("table"); //$NON-NLS-1$
            tableName.setValue(resolver.getCollectionTable(referenceField));
            propertyElement.getAttributes().setNamedItem(tableName);
            {
                // <key column="foo_id"/> (one per key in referenced entity).
                Element key = document.createElement("key"); //$NON-NLS-1$
                propertyElement.appendChild(key);
                for (FieldMetadata keyField : referenceField.getContainingType().getKeyFields()) {
                    Element elementColumn = document.createElement("column"); //$NON-NLS-1$
                    Attr columnName = document.createAttribute("name"); //$NON-NLS-1$
                    columnName.setValue(resolver.get(keyField));
                    elementColumn.getAttributes().setNamedItem(columnName);
                    key.appendChild(elementColumn);
                }
                // <index column="pos" />
                Element index = document.createElement("index"); //$NON-NLS-1$
                Attr indexColumn = document.createAttribute("column"); //$NON-NLS-1$
                indexColumn.setValue("pos"); //$NON-NLS-1$
                index.getAttributes().setNamedItem(indexColumn);
                propertyElement.appendChild(index);
                // many to many element
                Element manyToMany = newManyToManyElement(enforceDataBaseIntegrity, referenceField);
                propertyElement.appendChild(manyToMany);
            }
            return propertyElement;
        }
    }
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

private void generatorSubType(ComplexTypeMetadata parentComplexType, Element classElement) {
    boolean wasGeneratingConstraints;
    // Sub types/*from w  w  w. j a  v a 2 s  .  co  m*/
    if (!parentComplexType.getDirectSubTypes().isEmpty()) {
        if (parentComplexType.isInstantiable()) {
            /*
            <union-subclass name="CreditCardPayment" table="CREDIT_PAYMENT">
                   <property name="creditCardType" column=""/>
                   ...
               </union-subclass>
            */
            for (ComplexTypeMetadata subType : parentComplexType.getDirectSubTypes()) {
                Element unionSubclass = document.createElement("union-subclass"); //$NON-NLS-1$
                Attr name = document.createAttribute("name"); //$NON-NLS-1$
                name.setValue(ClassCreator.getClassName(subType.getName()));
                unionSubclass.setAttributeNode(name);

                Attr tableName = document.createAttribute("table"); //$NON-NLS-1$
                tableName.setValue(resolver.get(subType));
                unionSubclass.setAttributeNode(tableName);

                Collection<FieldMetadata> subTypeFields = subType.getFields();
                for (FieldMetadata subTypeField : subTypeFields) {
                    if (!parentComplexType.hasField(subTypeField.getName()) && !subTypeField.isKey()) {
                        unionSubclass.appendChild(subTypeField.accept(this));
                    }
                }
                if (!subType.getDirectSubTypes().isEmpty()) {
                    generatorSubType(subType, unionSubclass);
                }
                classElement.appendChild(unionSubclass);
            }
        } else {
            /*
            <subclass name="CreditCardPayment" discriminator-value="CREDIT">
                <property name="creditCardType" column="CCTYPE"/>
                ...
            </subclass>
             */
            wasGeneratingConstraints = generateConstrains;
            generateConstrains = false;
            try {
                for (ComplexTypeMetadata subType : parentComplexType.getDirectSubTypes()) {
                    Element subclass = document.createElement("subclass"); //$NON-NLS-1$
                    Attr name = document.createAttribute("name"); //$NON-NLS-1$
                    name.setValue(ClassCreator.getClassName(subType.getName()));
                    subclass.setAttributeNode(name);
                    Attr discriminator = document.createAttribute("discriminator-value"); //$NON-NLS-1$
                    discriminator.setValue(ClassCreator.PACKAGE_PREFIX + subType.getName());
                    subclass.setAttributeNode(discriminator);

                    Collection<FieldMetadata> subTypeFields = subType.getFields();
                    for (FieldMetadata subTypeField : subTypeFields) {
                        if (!parentComplexType.hasField(subTypeField.getName()) && !subTypeField.isKey()) {
                            subclass.appendChild(subTypeField.accept(this));
                        }
                    }
                    if (!subType.getDirectSubTypes().isEmpty()) {
                        generatorSubType(subType, subclass);
                    }
                    classElement.appendChild(subclass);
                }
            } finally {
                generateConstrains = wasGeneratingConstraints;
            }
        }
    }
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

private Element newManyToOneElement(ReferenceFieldMetadata referencedField, boolean enforceDataBaseIntegrity) {
    Element propertyElement = document.createElement("many-to-one"); //$NON-NLS-1$
    Attr propertyName = document.createAttribute("name"); //$NON-NLS-1$
    propertyName.setValue(referencedField.getName());
    Attr className = document.createAttribute("class"); //$NON-NLS-1$
    className.setValue(ClassCreator.getClassName(referencedField.getReferencedType().getName()));
    // fetch="join" lazy="false"
    Attr lazy = document.createAttribute("lazy"); //$NON-NLS-1$
    lazy.setValue("proxy"); //$NON-NLS-1$
    propertyElement.getAttributes().setNamedItem(lazy);
    Attr joinAttribute = document.createAttribute("fetch"); //$NON-NLS-1$
    joinAttribute.setValue("join"); //$NON-NLS-1$
    propertyElement.getAttributes().setNamedItem(joinAttribute);
    // foreign-key="..."
    String fkConstraintName = resolver.getFkConstraintName(referencedField);
    if (!fkConstraintName.isEmpty()) {
        Attr foreignKeyConstraintName = document.createAttribute("foreign-key"); //$NON-NLS-1$
        foreignKeyConstraintName.setValue(fkConstraintName);
        propertyElement.getAttributes().setNamedItem(foreignKeyConstraintName);
        Attr indexName = document.createAttribute("index"); //$NON-NLS-1$
        indexName.setValue("FK_" + fkConstraintName); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(indexName);
    }/*from  ww  w . j  a  v  a2  s  .  c o m*/
    // Not null
    if (referencedField.isMandatory() && generateConstrains) {
        Attr notNull = document.createAttribute("not-null"); //$NON-NLS-1$
        notNull.setValue("true"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(notNull);
    } else {
        Attr notNull = document.createAttribute("not-null"); //$NON-NLS-1$
        notNull.setValue("false"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(notNull);
    }
    // If data model authorizes fk integrity override, don't enforce database FK integrity.
    if (enforceDataBaseIntegrity) {
        // Ensure default settings for Hibernate are set (in case they change).
        Attr notFound = document.createAttribute("not-found"); //$NON-NLS-1$
        notFound.setValue("exception"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(notFound);
    } else {
        // Disables all warning/errors from Hibernate.
        Attr integrity = document.createAttribute("unique"); //$NON-NLS-1$
        integrity.setValue("false"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(integrity);

        Attr foreignKey = document.createAttribute("foreign-key"); //$NON-NLS-1$*
        // Disables foreign key generation for DDL.
        foreignKey.setValue("none"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(foreignKey);

        Attr notFound = document.createAttribute("not-found"); //$NON-NLS-1$
        notFound.setValue("ignore"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(notFound);
    }
    propertyElement.getAttributes().setNamedItem(propertyName);
    propertyElement.getAttributes().setNamedItem(className);
    // Cascade delete
    if (Boolean.parseBoolean(referencedField.<String>getData(SQL_DELETE_CASCADE))) {
        Attr cascade = document.createAttribute("cascade"); //$NON-NLS-1$
        cascade.setValue("lock, save-update, delete"); //$NON-NLS-1$
        propertyElement.getAttributes().setNamedItem(cascade);
    }
    isDoingColumns = true;
    isColumnMandatory = referencedField.isMandatory() && generateConstrains;
    this.parentElement = propertyElement;
    compositeKeyPrefix = referencedField.getName();
    {
        referencedField.getReferencedField().accept(this);
    }
    isDoingColumns = false;
    return propertyElement;
}

From source file:clus.statistic.ClassificationStat.java

@Override
public Element getPredictElement(Document doc) {
    NumberFormat fr = ClusFormat.SIX_AFTER_DOT;
    Element stats = doc.createElement("ClassificationStat");
    Attr examples = doc.createAttribute("examples");
    examples.setValue(fr.format(m_SumWeight));
    stats.setAttributeNode(examples);/*w w  w  .  j a  v  a2s  .  c  o  m*/
    Element majorities = doc.createElement("MajorityClasses");
    stats.appendChild(majorities);
    if (m_MajorityClasses != null) {
        for (int i = 0; i < m_NbTarget; i++) {
            Element majority = doc.createElement("Target");
            majorities.appendChild(majority);

            majority.setTextContent(m_Attrs[i].getValue(m_MajorityClasses[i]));

            Attr name = doc.createAttribute("name");
            name.setValue(m_Attrs[i].getName());
            majority.setAttributeNode(name);
        }
    } else {
        Element majority = doc.createElement("Attribute");
        majorities.appendChild(majority);
    }
    Element distribution = doc.createElement("Distributions");
    stats.appendChild(distribution);
    for (int j = 0; j < m_NbTarget; j++) {
        Element target = doc.createElement("Target");
        distribution.appendChild(target);
        Attr name = doc.createAttribute("name");
        name.setValue(m_Attrs[j] + "");
        target.setAttributeNode(name);
        for (int i = 0; i < m_ClassCounts[j].length; i++) {
            Element value = doc.createElement("Value");
            target.appendChild(value);
            name = doc.createAttribute("name");
            name.setValue(m_Attrs[j].getValue(i));
            value.setAttributeNode(name);
            value.setTextContent(m_ClassCounts[j][i] + "");
        }
    }
    return stats;
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

@Override
public Element visit(ComplexTypeMetadata complexType) {
    if (complexType.getKeyFields().isEmpty()) {
        throw new IllegalArgumentException("Type '" + complexType.getName() + "' has no key."); //$NON-NLS-1$ //$NON-NLS-2$
    }//from  w w  w. java2s.c o  m
    if (!complexType.getSuperTypes().isEmpty()) {
        return null;
    }

    tableNames.push(resolver.get(complexType));
    Element classElement;
    {
        String generatedClassName = ClassCreator.getClassName(complexType.getName());
        classElement = document.createElement("class"); //$NON-NLS-1$
        Attr className = document.createAttribute("name"); //$NON-NLS-1$
        className.setValue(generatedClassName);
        classElement.getAttributes().setNamedItem(className);
        Attr classTable = document.createAttribute("table"); //$NON-NLS-1$
        classTable.setValue(tableNames.peek());
        classElement.getAttributes().setNamedItem(classTable);
        // Adds schema name (if set in configuration)
        String value = dataSource.getAdvancedProperties().get("hibernate.default_schema"); //$NON-NLS-1
        if (value != null) {
            Attr classSchema = document.createAttribute("schema"); //$NON-NLS-1$
            classSchema.setValue(value);
            classElement.getAttributes().setNamedItem(classSchema);
        }
        // dynamic-update="true"
        Attr dynamicUpdate = document.createAttribute("dynamic-update"); //$NON-NLS-1$
        dynamicUpdate.setValue("true"); //$NON-NLS-1$
        classElement.getAttributes().setNamedItem(dynamicUpdate);
        // dynamic-insert="true"
        Attr dynamicInsert = document.createAttribute("dynamic-insert"); //$NON-NLS-1$
        dynamicInsert.setValue("true"); //$NON-NLS-1$
        classElement.getAttributes().setNamedItem(dynamicInsert);
        // <cache usage="read-write" include="non-lazy"/>
        Element cacheElement = document.createElement("cache"); //$NON-NLS-1$
        Attr usageAttribute = document.createAttribute("usage"); //$NON-NLS-1$
        usageAttribute.setValue("read-write"); //$NON-NLS-1$
        cacheElement.getAttributes().setNamedItem(usageAttribute);
        Attr includeAttribute = document.createAttribute("include"); //$NON-NLS-1$
        includeAttribute.setValue("non-lazy"); //$NON-NLS-1$
        cacheElement.getAttributes().setNamedItem(includeAttribute);
        Attr regionAttribute = document.createAttribute("region"); //$NON-NLS-1$
        regionAttribute.setValue("region"); //$NON-NLS-1$
        cacheElement.getAttributes().setNamedItem(regionAttribute);
        classElement.appendChild(cacheElement);

        Collection<FieldMetadata> keyFields = complexType.getKeyFields();
        List<FieldMetadata> allFields = new ArrayList<FieldMetadata>(complexType.getFields());

        // Process key fields first (Hibernate DTD enforces IDs to be declared first in <class/> element).
        Element idParentElement = classElement;
        if (keyFields.size() > 1) {
            /*
            <composite-id>
                    <key-property column="x_enterprise" name="x_enterprise"/>
                    <key-property column="x_id" name="x_id"/>
                </composite-id>
             */
            compositeId = true;
            idParentElement = document.createElement("composite-id"); //$NON-NLS-1$
            classElement.appendChild(idParentElement);

            Attr classAttribute = document.createAttribute("class"); //$NON-NLS-1$
            classAttribute.setValue(generatedClassName + "_ID"); //$NON-NLS-1$
            idParentElement.getAttributes().setNamedItem(classAttribute);

            Attr mappedAttribute = document.createAttribute("mapped"); //$NON-NLS-1$
            mappedAttribute.setValue("true"); //$NON-NLS-1$
            idParentElement.getAttributes().setNamedItem(mappedAttribute);
        }
        for (FieldMetadata keyField : keyFields) {
            idParentElement.appendChild(keyField.accept(this));
            boolean wasRemoved = allFields.remove(keyField);
            if (!wasRemoved) {
                LOGGER.error(
                        "Field '" + keyField.getName() + "' was expected to be removed from processed fields."); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
        compositeId = false;
        // Generate a discriminator (if needed).
        if (!complexType.getSubTypes().isEmpty() && !complexType.isInstantiable()) {
            // <discriminator column="PAYMENT_TYPE" type="string"/>
            Element discriminator = document.createElement("discriminator"); //$NON-NLS-1$
            Attr name = document.createAttribute("column"); //$NON-NLS-1$
            name.setValue(DISCRIMINATOR_NAME);
            discriminator.setAttributeNode(name);
            Attr type = document.createAttribute("type"); //$NON-NLS-1$
            type.setValue("string"); //$NON-NLS-1$
            discriminator.setAttributeNode(type);
            classElement.appendChild(discriminator);
        }
        // Process this type fields
        boolean wasGeneratingConstraints = generateConstrains;
        try {
            if (complexType.getName().startsWith("X_")) { //$NON-NLS-1$
                Integer usageNumber = complexType.<Integer>getData(TypeMapping.USAGE_NUMBER);
                // TMDM-8283: Don't turn on constraint generation even if reusable type is used only once.
                generateConstrains = generateConstrains && (usageNumber == null || usageNumber <= 1);
            }
            for (FieldMetadata currentField : allFields) {
                Element child = currentField.accept(this);
                if (child == null) {
                    throw new IllegalArgumentException(
                            "Field type " + currentField.getClass().getName() + " is not supported."); //$NON-NLS-1$ //$NON-NLS-2$
                }
                classElement.appendChild(child);
            }
        } finally {
            generateConstrains = wasGeneratingConstraints;
        }
        // Sub types
        generatorSubType(complexType, classElement);
    }
    tableNames.pop();

    return classElement;
}

From source file:com.amalto.core.storage.hibernate.MappingGenerator.java

private void setIndexName(FieldMetadata field, String fieldName, Attr indexName) {
    String prefix = field.getContainingType().getName();
    if (!tableNames.isEmpty() && field.getContainingType().getSuperTypes().isEmpty()) {
        prefix = tableNames.peek();//w  w  w  .j av  a 2  s. c o  m
    }
    indexName.setValue(resolver.getIndex(fieldName, prefix)); //
}

From source file:com.legstar.jaxb.gen.CobolJAXBCustomizer.java

/**
 * JAXB needs to know the LegStar extension prefix used. Here we lookup the
 * extension attribute and version if they are found, we add to them
 * otherwise we create new attributes./*from www  .  j  ava 2s .c  o m*/
 * <p/>
 * 
 * @param xsd the XML Schema
 * @param jaxbPrefix the JAXB namespace prefix
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void injectJaxbExtensionAttributes(final XmlSchema xsd, final String jaxbPrefix) {

    // Lookup the LegStar namespace prefix
    String coxbPrefix = COXB_DEFAULT_NAMESPACE_PREFIX;
    NamespacePrefixList nsList = xsd.getNamespaceContext();
    for (String prefix : nsList.getDeclaredPrefixes()) {
        if (nsList.getNamespaceURI(prefix).equals(CobolMarkup.NS)) {
            coxbPrefix = prefix;
            break;
        }
    }

    // Retrieve extension attributes if any
    Map metaInfoMap = xsd.getMetaInfoMap();
    Map<QName, Attr> extensionMap = null;
    if (metaInfoMap != null) {
        extensionMap = (Map<QName, Attr>) metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
    } else {
        metaInfoMap = new LinkedHashMap();
        xsd.setMetaInfoMap(metaInfoMap);
    }
    if (extensionMap == null) {
        extensionMap = new HashMap<QName, Attr>();
    }

    // Extension attributes are DOM attributes
    Document doc = _db.newDocument();

    // Make sure the JAXB version extension is added
    QName versionQName = new QName(JAXB_NAMESPACE, JAXB_VERSION_ATTR_NAME);
    Attr attrib = doc.createAttribute(jaxbPrefix + ':' + JAXB_VERSION_ATTR_NAME);
    attrib.setValue(JAXB_VERSION_ATTR_VALUE);
    extensionMap.put(versionQName, attrib);

    /*
     * JAXB extension prefixes might already be present in which case we
     * make sure the legstar extension is there too. Extension prefixes are
     * specified as a whitespace-separated list of namespace prefixes.
     */

    QName extpfxQName = new QName(JAXB_NAMESPACE, JAXB_EXTENSION_BINDING_PREFIXES_ATTR_NAME);
    attrib = extensionMap.get(extpfxQName);
    if (attrib == null) {
        attrib = doc.createAttribute(jaxbPrefix + ':' + JAXB_EXTENSION_BINDING_PREFIXES_ATTR_NAME);
    }
    String extpfx = attrib.getValue();
    if (extpfx == null || extpfx.length() == 0) {
        extpfx = coxbPrefix;
    } else {
        boolean hasCoxbPrefix = false;
        StringTokenizer tokenizer = new StringTokenizer(extpfx, " ");
        while (tokenizer.hasMoreTokens()) {
            if (tokenizer.nextToken().equals(coxbPrefix)) {
                hasCoxbPrefix = true;
                break;
            }
        }
        if (!hasCoxbPrefix) {
            extpfx = extpfx + " " + coxbPrefix;
        }
    }
    attrib.setValue(extpfx);
    extensionMap.put(extpfxQName, attrib);

    metaInfoMap.put(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES, extensionMap);
}