Example usage for org.jdom2 Namespace getURI

List of usage examples for org.jdom2 Namespace getURI

Introduction

In this page you can find the example usage for org.jdom2 Namespace getURI.

Prototype

public String getURI() 

Source Link

Document

This returns the namespace URI for this Namespace.

Usage

From source file:edu.unc.lib.dl.cdr.services.AbstractFedoraEnhancement.java

License:Apache License

protected void setExclusiveTripleRelation(PID pid, String predicate, Namespace namespace, PID exclusivePID,
        Document foxml) throws FedoraException {
    List<String> rel = FOXMLJDOMUtil.getRelationValues(predicate, namespace, FOXMLJDOMUtil.getRelsExt(foxml));
    String predicateUri = namespace.getURI() + predicate;
    if (rel != null) {
        String valueString = exclusivePID.toString();
        if (rel.contains(valueString)) {
            rel.remove(valueString);/* w w  w. ja va2s  . com*/
        } else {
            // add missing rel
            service.getManagementClient().addObjectRelationship(pid, predicateUri, exclusivePID);
        }
        // remove any other same predicate triples
        for (String oldValue : rel) {
            service.getManagementClient().purgeObjectRelationship(pid, predicateUri, new PID(oldValue));
        }
    } else {
        // add missing rel
        service.getManagementClient().addObjectRelationship(pid, predicateUri, exclusivePID);
    }
}

From source file:edu.unc.lib.dl.cdr.services.AbstractFedoraEnhancement.java

License:Apache License

protected void setExclusiveTripleValue(PID pid, String predicate, Namespace namespace, String newExclusiveValue,
        String datatype, Document foxml) throws FedoraException {
    List<String> rel = FOXMLJDOMUtil.getRelationValues(predicate, namespace, FOXMLJDOMUtil.getRelsExt(foxml));
    String predicateUri = namespace.getURI() + predicate;
    if (rel != null) {
        if (rel.contains(newExclusiveValue)) {
            rel.remove(newExclusiveValue);
        } else {/*from w  ww  .  j  a  v a 2 s  .c  o m*/
            // add missing rel
            service.getManagementClient().addLiteralStatement(pid, predicateUri, newExclusiveValue, datatype);
        }
        // remove any other same predicate triples
        for (String oldValue : rel) {
            service.getManagementClient().purgeLiteralStatement(pid, predicateUri, oldValue, datatype);
        }
    } else {
        // add missing rel
        service.getManagementClient().addLiteralStatement(pid, predicateUri, newExclusiveValue, datatype);
    }
}

From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.TypesExtractorImpl.java

License:Apache License

/**
 * This method traverses all the elements of each input document in order to find all the namespace URI to prefix mappings present at the documents.
 * With that information, the map between namespace URIs and their known prefixes is filled. It is used later to solve which prefix should be bound 
 * to each namespace URI./* www.j ava  2  s .co m*/
 */
private void fillKnownNamespaceToPrefixMappings() {
    Filter<Element> elementFilter = Filters.element();
    for (int i = 0; i < xmlDocuments.size(); i++) {
        for (Element element : xmlDocuments.get(i).getDescendants(elementFilter)) {
            for (Namespace namespace : element.getNamespacesInScope()) {
                //We do not add XSI to the known namespaces 
                if (namespace.getURI().equalsIgnoreCase(XSI_NAMESPACE_URI))
                    continue;
                String uri = namespace.getURI();
                String prefix = namespace.getPrefix();
                SortedSet<String> currentPrefixes = prefixNamespaceMapping.get(uri);
                if (currentPrefixes == null) {
                    currentPrefixes = new TreeSet<String>();
                    prefixNamespaceMapping.put(uri, currentPrefixes);
                }
                currentPrefixes.add(prefix);
            }
            //If the element belongs to the empty namespace (empty string) with no prefix, we must add 
            //this to the prefix-namespace mapping explicitly
            if (element.getNamespacePrefix().equals("") && element.getNamespaceURI().equals("")) {
                String uri = "";
                String prefix = "";
                SortedSet<String> currentPrefixes = prefixNamespaceMapping.get(uri);
                if (currentPrefixes == null) {
                    currentPrefixes = new TreeSet<>();
                    prefixNamespaceMapping.put(uri, currentPrefixes);
                }
                currentPrefixes.add(prefix);
            }
        }
    }
}

From source file:es.upm.dit.xsdinferencer.generation.generatorimpl.schemageneration.XMLSchemaDocumentGenerator.java

License:Apache License

/**
 * It generates the XSD file of the targetNamespace given at the constructor, taking into account that 
 * the main namespace is the one given at the constructor.
 * /*from w  w w  .ja va 2 s.c om*/
 * @param schema the schema object
 * @param configuration the inference configuration
 * 
 * @return a JDOM2 {@link Document} object containing the XSD contents.
 * 
 * @see SchemaDocumentGenerator#generateSchemaDocument(Schema, XSDInferenceConfiguration)
 */
@Override
public Document generateSchemaDocument(Schema schema, XSDInferenceConfiguration configuration) {
    //      if(!configuration.getElementsGlobal()==false || 
    //            !configuration.getComplexTypesGlobal()==true ||
    //            !configuration.getSimpleTypesGlobal()==true
    //            )
    //         throw new UnsupportedOperationException("Not implemented yet.");
    //
    checkArgument(schema.getNamespacesToPossiblePrefixMappingModifiable().containsKey(mainNamespace),
            "The main namespace must be a known namespace");
    checkArgument(schema.getNamespacesToPossiblePrefixMappingModifiable().containsKey(targetNamespace),
            "The target namespace must be a known namespace");
    //      checkArgument(!schema.getNamespacesToPossiblePrefixMappingModifiable().containsKey(XSD_NAMESPACE_URI),"The XSD namespace must not be a known namespace");
    //      checkArgument(!schema.getNamespacesToPossiblePrefixMappingModifiable().containsKey(XSI_NAMESPACE_URI),"The XSI namespace must not be a known namespace");
    Map<String, String> namespaceURIToPrefixMappings = schema.getSolvedNamespaceMappings();
    if (configuration.getSkipNamespaces().contains(targetNamespace)) {
        throw new IllegalArgumentException("This is an skipped namespace, so its XSD should not be generated");
    }
    if (targetNamespace.equals(XSD_NAMESPACE_URI))
        System.err.println(
                "The XML Schema namespace is being considered as a target namespace in your documents. Independing of the inferred schemas, the only valid XSD for an XSD would be the normative one present at its first RFC");
    Namespace xsdNamespace = Namespace.getNamespace(XSD_NAMESPACE_PREFIX.replace(":", ""), XSD_NAMESPACE_URI);
    List<Namespace> namespaceDeclarations = getNamespaceDeclarations(namespaceURIToPrefixMappings,
            xsdNamespace);
    Element elementSchema = new Element("schema", xsdNamespace);
    for (int i = 0; i < namespaceDeclarations.size(); i++) {
        Namespace currentNamespace = namespaceDeclarations.get(i);
        elementSchema.addNamespaceDeclaration(currentNamespace);
        String currentNamespaceUri = currentNamespace.getURI();
        if (!targetNamespace.equals(mainNamespace) && !currentNamespaceUri.equals(mainNamespace))
            continue;
        if (currentNamespace.equals(Namespace.XML_NAMESPACE)
                && (!schema.getAttributes().containsRow(XSDInferenceConfiguration.XML_NAMESPACE_URI)
                        && !schema.getElements().containsRow(XSDInferenceConfiguration.XML_NAMESPACE_URI))) {
            continue;
        }
        if (currentNamespaceUri.equals(XSD_NAMESPACE_URI)
                && !namespaceURIToPrefixMappings.containsKey(XSD_NAMESPACE_URI))
            continue;
        if (targetNamespace.equals(currentNamespaceUri)
                || (currentNamespaceUri.equals("") && (fileNameGenerator == null)))
            continue;
        if (currentNamespaceUri.equals("") && !currentNamespaceUri.equals(mainNamespace)
                && !schema.getElements().containsRow(""))
            continue;
        Element importElement = new Element("import", xsdNamespace);
        if (!currentNamespaceUri.equals("")) {
            Attribute namespaceAttr = new Attribute("namespace", currentNamespaceUri);
            importElement.setAttribute(namespaceAttr);
        }
        if (fileNameGenerator != null && !configuration.getSkipNamespaces().contains(currentNamespaceUri)) {
            String fileName = fileNameGenerator.getSchemaDocumentFileName(currentNamespaceUri,
                    namespaceURIToPrefixMappings);
            Attribute schemaLocationAttr = new Attribute("schemaLocation", fileName);
            importElement.setAttribute(schemaLocationAttr);
        }
        elementSchema.addContent(importElement);
    }

    if (!targetNamespace.equals("")) {
        Attribute targetNamespaceAttr = new Attribute("targetNamespace", targetNamespace);
        elementSchema.setAttribute(targetNamespaceAttr);
    }
    SortedSet<SimpleType> sortedSimpleTypes = new TreeSet<>(new SimpleTypeComparator());
    sortedSimpleTypes.addAll(schema.getSimpleTypes().values());
    SortedSet<ComplexType> sortedComplexTypes = new TreeSet<>(new ComplexTypeComparator());
    sortedComplexTypes.addAll(schema.getComplexTypes().values());
    //CONTINUE FROM HERE: Generate sorted sets for SchemaElement and SchemaAttribute objects and use them where needed.
    Attribute elementFormDefault = new Attribute("elementFormDefault", "qualified");
    elementSchema.setAttribute(elementFormDefault);
    Document resultingDocument = new Document(elementSchema);
    if (targetNamespace.equals(mainNamespace)) {
        //First, we declare global SimpleTypes.
        //If simpleTypesGlobal is true, any enumeration will be declared as a global simple type.
        //if not, simple types of complex types which have attributes but not children will be declared globally 
        //(due to limitations of XSD, they may not be declared locally together with the attributes info)
        if (configuration.getSimpleTypesGlobal()) {
            for (SimpleType simpleType : sortedSimpleTypes) {
                if (!simpleType.isEnum() || simpleType.isEmpty())
                    continue;
                Element simpleTypeElement = generateSimpleType(simpleType, false, configuration, xsdNamespace);
                elementSchema.addContent(simpleTypeElement);
            }
        } else {
            for (ComplexType complexType : sortedComplexTypes) {
                SimpleType simpleType = complexType.getTextSimpleType();
                if (complexType.getAttributeList().isEmpty() || !(complexType.getAutomaton().nodeCount() == 0)
                        || !simpleType.isEnum() || simpleType.isEmpty())
                    continue;
                Element simpleTypeElement = generateSimpleType(simpleType, false, configuration, xsdNamespace);
                elementSchema.addContent(simpleTypeElement);
            }
        }
        //Global complexType elements are only generated in the main schema (i.e. the one whose targetNamespace is equal to mainNamespace)
        if (configuration.getComplexTypesGlobal()) {
            for (ComplexType complexType : sortedComplexTypes) {
                boolean hasNoChildren = complexType.getRegularExpression().equals(new EmptyRegularExpression());
                boolean hasNoAttributes = complexType.getAttributeList().size() == 0;
                boolean hasNoComments = complexType.getComments().size() == 0;
                //               boolean simpleTypeIsNotEmpty = !complexType.getTextSimpleType().isEmpty();
                boolean simpleTypeIsWhiteSpaceOnlyOrEmpty = !(complexType.getTextSimpleType().isEmpty()
                        || complexType.getTextSimpleType().consistOnlyOfWhitespaceCharacters());
                if (hasNoChildren && hasNoAttributes && simpleTypeIsWhiteSpaceOnlyOrEmpty && hasNoComments)
                    continue; //Because the elements which are linked to this ComplexType at our internal model 
                              //will be linked to an XSD simple type elsewhere, either a builtin or a custom one.
                Element complexTypeElement = generateComplexType(configuration, complexType, false,
                        targetNamespace, namespaceURIToPrefixMappings, mainNamespace, xsdNamespace);
                elementSchema.addContent(complexTypeElement);
            }
        }
    }
    //If there are many namespaces and the workaround is disabled, we must declare global attributes.
    //If the targetNamespace is not the mainNamespace, we must declare all the attributes.
    //if the target namespace is the main namespace, we do not need to declare anything, because the complex types which hold the attributes 
    //are also in the main namespace.
    if ((namespaceURIToPrefixMappings.size() - configuration.getSkipNamespaces().size()) > 1) {

        SortedMap<String, SchemaAttribute> globalAttributeCandidates = new TreeMap<>(
                schema.getAttributes().row(targetNamespace));
        if (!targetNamespace.equals(mainNamespace) && !targetNamespace.equals("")) {
            globalAttributesLoop: for (Map.Entry<String, SchemaAttribute> schemaAttributeEntry : globalAttributeCandidates
                    .entrySet()) {
                SchemaAttribute schemaAttribute = schemaAttributeEntry.getValue();
                //First, we check if the attribute has been already declared when the workaround is disabled. 
                //If so, we update the "use" property.
                //The type should have been already merged.
                if (!configuration.getStrictValidRootDefinitionWorkaround()) {
                    List<Element> alreadyGeneratedAttributeElements = elementSchema.getChildren("attribute",
                            xsdNamespace);
                    for (int i = 0; i < alreadyGeneratedAttributeElements.size(); i++) {
                        Element currentAttributeElement = alreadyGeneratedAttributeElements.get(i);
                        if (currentAttributeElement.getAttributeValue("name")
                                .equals(schemaAttribute.getName())) {
                            continue globalAttributesLoop;
                        }
                    }
                }
                Element attributeOrAttributeGroupElement = generateAttribute(schemaAttribute, true,
                        configuration, namespaceURIToPrefixMappings, targetNamespace, mainNamespace,
                        schemaAttributeEntry.getKey(), xsdNamespace);
                elementSchema.addContent(attributeOrAttributeGroupElement);
            }
        }
    }

    //Now, we declare global elements.
    //An element will be declared globally if and only if: 
    //1-elementsGlobal is true in the configuration
    //2-The element is a valid root
    //3-The element is in a namespace other than the main namespace. Note that the element WILL be surrounded by the corresponding group if the workaround is enabled.
    //Another important remark: Iterating over a set copy implies iterating over DISTINCT SchemaElements, so if two keys pointed to equal SchemaElements, we would generate it only once-
    SortedSet<SchemaElement> schemaElementsAtTargetNamespace = new TreeSet<>(new SchemaElementComparator());
    schemaElementsAtTargetNamespace.addAll(schema.getElements().row(targetNamespace).values());
    globalSchemaElementsLoop: for (SchemaElement schemaElement : schemaElementsAtTargetNamespace) {
        //         if(!configuration.getElementsGlobal()&&
        //               !schemaElement.isValidRoot()&&
        //               (targetNamespace.equals(mainNamespace)||configuration.getStrictValidRootDefinitionWorkaround()))
        if (!configuration.getElementsGlobal() && !schemaElement.isValidRoot()
                && (targetNamespace.equals(mainNamespace)))
            continue;
        //         for(Element currentElement:elementSchema.getContent(Filters.element("element",xsdNamespace))){
        //            if(schemaElement.getName().equals(currentElement.getAttributeValue("name")))
        //               continue globalSchemaElementsLoop;
        //         }
        String possibleGroupName = schemaElement.getName() + configuration.getTypeNamesAncestorsSeparator()
                + schemaElement.getType().getName();
        for (Element currentElement : elementSchema.getContent(Filters.element("group", xsdNamespace))) {
            if (possibleGroupName.equals(currentElement.getAttributeValue("name")))
                continue globalSchemaElementsLoop;
        }
        Element elementOrGroupElement = generateElement(schemaElement, true, configuration, targetNamespace,
                mainNamespace, null, namespaceURIToPrefixMappings, xsdNamespace);
        if (elementOrGroupElement.getName().equals("element")) {
            for (Element currentElement : elementSchema.getChildren("element", xsdNamespace)) {
                if (schemaElement.getName().equals(currentElement.getAttributeValue("name")))
                    continue globalSchemaElementsLoop;
            }
        }
        elementSchema.addContent(elementOrGroupElement);
    }
    return resultingDocument;
}

From source file:es.upm.dit.xsdinferencer.generation.generatorimpl.schemageneration.XMLSchemaDocumentGenerator.java

License:Apache License

/**
 * Generates an element that describes an attribute (including name, type and optionality)
 * @param schemaAttribute the attribute to describe
 * @param isGlobal whether it will be declared globally or not
 * @param configuration the inference configuration
 * @param namespaceURIToPrefixMappings the solved mappings between namespace URIs and prefixes
 * @param targetNamespace the target namespace of the XSD that is being currently generated
 * @param mainNamespace the main namespace
 * @param schemaAttributeKey the key used at the {@link Schema} attributes structures, which will be 
 * also used to name attribute groups used at inter-namespace importing and exporting when the 
 * workaround is enabled./*from  ww  w.  ja  va2s  . co m*/
 * @param xsdNamespace the XSD namespace
 * @return a JDOM2 {@link Element} describing the attribute
 */
private Element generateAttribute(SchemaAttribute schemaAttribute, boolean isGlobal,
        XSDInferenceConfiguration configuration, Map<String, String> namespaceURIToPrefixMappings,
        String targetNamespace, String mainNamespace, String schemaAttributeKey, Namespace xsdNamespace) {

    Element attributeElement = new Element("attribute", xsdNamespace);
    boolean workaround = configuration.getStrictValidRootDefinitionWorkaround();
    boolean belongsToSkippedNamespace = configuration.getSkipNamespaces().contains(
            schemaAttribute.getNamespace()) || schemaAttribute.getNamespace().equals(xsdNamespace.getURI());
    if ((schemaAttribute.getNamespace().equals(mainNamespace) || schemaAttribute.getNamespace().equals(""))
            || (isGlobal && (!workaround))) {
        fillNormalAttributeElement(schemaAttribute, attributeElement, configuration,
                namespaceURIToPrefixMappings, targetNamespace, mainNamespace, isGlobal, xsdNamespace);

        return attributeElement;
    } else if (!isGlobal && (!workaround || belongsToSkippedNamespace)) {
        Attribute attributeRefAttr = new Attribute("ref", "");
        String namespacePrefix = namespaceURIToPrefixMappings.get(schemaAttribute.getNamespace());
        String attributeRefValue = schemaAttribute.getName();
        if (!namespacePrefix.equals(""))
            attributeRefValue = namespacePrefix + ":" + attributeRefValue;
        attributeRefAttr.setValue(attributeRefValue);
        attributeElement.setAttribute(attributeRefAttr);
        return attributeElement;
    } else {
        Element attributeGroupElement = new Element("attributeGroup", xsdNamespace);
        if (isGlobal) {
            Attribute attributeGroupNameAttr = new Attribute("name", "");
            attributeGroupNameAttr.setValue(schemaAttributeKey);
            attributeGroupElement.setAttribute(attributeGroupNameAttr);
            fillNormalAttributeElement(schemaAttribute, attributeElement, configuration,
                    namespaceURIToPrefixMappings, targetNamespace, mainNamespace, isGlobal, xsdNamespace);
            attributeGroupElement.addContent(attributeElement);
            return attributeGroupElement;
        } else {
            Attribute attributeGroupRefAttr = new Attribute("ref", "");
            String namespacePrefix = namespaceURIToPrefixMappings.get(schemaAttribute.getNamespace());
            String refValue = "";
            if (!namespacePrefix.equals(""))
                refValue = namespacePrefix + ":";
            refValue += schemaAttributeKey;
            attributeGroupRefAttr.setValue(refValue);
            attributeGroupElement.setAttribute(attributeGroupRefAttr);
            Attribute attributeUseAttr = new Attribute("use", "");
            String attributeUseValue = schemaAttribute.isOptional() ? "optional" : "required";
            attributeUseAttr.setValue(attributeUseValue);
            attributeElement.setAttribute(attributeUseAttr);
            return attributeGroupElement;
        }
    }

}

From source file:io.smartspaces.workbench.project.jdom.JdomProjectReader.java

License:Apache License

/**
 * Process an element and return a new project.
 *
 * @param projectElement// www .  j a v  a  2  s .  c o  m
 *          element to process
 *
 * @return project representing the element
 */
Project makeProjectFromElement(Element projectElement) {
    Namespace projectNamespace = projectElement.getNamespace();

    if (!PROJECT_ELEMENT_NAME_PROJECT.equals(projectElement.getName())) {
        throw new SimpleSmartSpacesException("Invalid project root element name " + projectElement.getName());
    }

    // When an xi:include statement is used, the included elements do not pick
    // up the default namespace.
    if (!Namespace.NO_NAMESPACE.equals(projectNamespace)) {
        getLog().info(String.format("Applying default namespace '%s' to project element tree",
                projectNamespace.getURI()));
        applyDefaultNamespaceRecursively(projectElement, projectNamespace, true);
    }

    String projectType = getProjectType(projectElement);
    Project project = getWorkbench().getProjectTypeRegistry().newProject(projectType);

    project.setPlatform(getProjectPlatform(projectElement));

    processPrototypeChain(project, projectNamespace, projectElement);
    configureProjectFromElement(project, projectNamespace, projectElement);

    if (project.getSmartSpacesVersionRange() == null) {
        getLog().warn("Did not specify a range of needed Smart Spaces versions. Setting default to "
                + SMARTSPACES_VERSION_RANGE_DEFAULT);
        project.setSmartSpacesVersionRange(SMARTSPACES_VERSION_RANGE_DEFAULT);
    }

    if (failure) {
        throw new SimpleSmartSpacesException("Project specification had errors");
    }

    return project;
}

From source file:net.instantcom.mm7.MM7Message.java

License:Open Source License

@Override
public void load(Element element) {
    Element body = element.getChild("Body", element.getNamespace());

    // Extract MM7 namespace from SOAP body
    Iterator<?> i = body.getDescendants(new ElementFilter());
    while (i.hasNext()) {
        Element e = (Element) i.next();
        Namespace ns = e.getNamespace();
        if (ns != null && ns.getURI().contains("MM7")) {
            this.namespace = ns;
            break;
        }/*  w  ww  .  j  ava 2s  . co m*/
    }

    if (this.namespace == null) {
        throw new IllegalStateException("can't autodetect MM7 namespace: " + body.toString());
    }

    Element header = element.getChild("Header", element.getNamespace());
    setTransactionId(header.getChildTextTrim("TransactionID", namespace));
}

From source file:org.cloudsimulator.xml.rdf.xmlrdfconverter.BusinessConfigurationToXmlRdf.java

License:Open Source License

public static Element createBusinessConfigurationElement(final Namespace nameSpace,
        final Document documentParent, final BusinessConfiguration businessConfiguration,
        final String uriBusinessConfiguration) {
    Element businessConfigurationElement = documentParent.createElementNS(nameSpace.getURI(),
            nameSpace.getPrefix() + ":BusinessConfiguration");

    businessConfigurationElement.setAttributeNS(NameSpaceRepository.RDF.getURI(),
            NameSpaceRepository.RDF.getPrefix() + ":about", uriBusinessConfiguration);
    businessConfigurationElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent,
            "hasName", businessConfiguration.getHasName()));
    businessConfigurationElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent,
            "hasIdentifier", businessConfiguration.getHasIdentifier()));
    businessConfigurationElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent,
            "hasContractId", businessConfiguration.getHasContractId()));

    for (User creator : businessConfiguration.getCreatorList()) {
        if (creator != null) {
            businessConfigurationElement.appendChild(
                    XmlUtility.createResourceElement(nameSpace, documentParent, "createdBy", creator.getUri()));
        }//from w  w w .  j  ava2s.co m
    }

    boolean firstIcaroApplicationOrTenant = true;
    Element hasPartElement = documentParent.createElementNS(nameSpace.getURI(),
            nameSpace.getPrefix() + ":hasPart");
    for (IcaroApplication icaroApplication : businessConfiguration.getIcaroApplicationList()) {
        if (icaroApplication != null) {
            if (firstIcaroApplicationOrTenant) {
                businessConfigurationElement.appendChild(hasPartElement);
                firstIcaroApplicationOrTenant = false;
            }
            Element icaroApplicationElement = IcaroApplicationToXmlRdf.createIcaroApplicationElement(nameSpace,
                    documentParent, icaroApplication,
                    IcaroApplication.getPathUri() + icaroApplication.getTypeRdf().replace("&app;", "") + ":"
                            + businessConfiguration.getLocalUri() + "_"
                            + businessConfiguration.getIcaroApplicationList().indexOf(icaroApplication));
            hasPartElement.appendChild(icaroApplicationElement);
        }
    }
    for (IcaroTenant icaroTenant : businessConfiguration.getIcaroTenantList()) {
        if (icaroTenant != null) {
            if (firstIcaroApplicationOrTenant) {
                businessConfigurationElement.appendChild(hasPartElement);
                firstIcaroApplicationOrTenant = false;
            }
            Element icaroTenantElement = IcaroTenantToXmlRdf.createIcaroTenantElement(nameSpace, documentParent,
                    icaroTenant, IcaroTenant.getPathUri() + "Tenant:" + businessConfiguration.getLocalUri()
                            + "_" + businessConfiguration.getIcaroTenantList().indexOf(icaroTenant));
            // Element icaroTenantElement =
            // IcaroTenantToXmlRdf.createIcaroTenantElement(nameSpace,
            // documentParent, icaroTenant, IcaroTenant.getPathUri()
            // +
            // icaroTenant.getIsTenantOf().substring(IcaroApplication.getPathUri().length(),
            // icaroTenant.getIsTenantOf().lastIndexOf(":")) + "Tenant:" +
            // businessConfiguration.getLocalUri() + "_"
            // +
            // businessConfiguration.getIcaroTenantList().indexOf(icaroTenant));
            hasPartElement.appendChild(icaroTenantElement);
            // TODO Correggere
        }
    }

    boolean firstSlAgreement = true;
    Element hasSLAElement = documentParent.createElementNS(nameSpace.getURI(),
            nameSpace.getPrefix() + ":hasSLA");
    for (SLAgreement slAgreement : businessConfiguration.getSlAgreementList()) {
        if (slAgreement != null) {
            if (firstSlAgreement) {
                businessConfigurationElement.appendChild(hasSLAElement);
                firstSlAgreement = false;
            }
            hasSLAElement.appendChild(SLAgreementToXmlRdf.createSLAgreementElement(nameSpace, documentParent,
                    slAgreement, slAgreement.getPathUri() + businessConfiguration.getLocalUri() + "_"
                            + businessConfiguration.getSlAgreementList().indexOf(slAgreement)));
        }
    }

    return businessConfigurationElement;
}

From source file:org.cloudsimulator.xml.rdf.xmlrdfconverter.DataCenterToXmlRdf.java

License:Open Source License

public static Element createDataCenterElement(final Namespace nameSpace, final Document documentParent,
        final DataCenter dataCenter) {
    Element dataCenterElement = documentParent.createElementNS(nameSpace.getURI(),
            nameSpace.getPrefix() + ":DataCenter");

    dataCenterElement.setAttributeNS(NameSpaceRepository.RDF.getURI(),
            NameSpaceRepository.RDF.getPrefix() + ":about", dataCenter.getUri());
    dataCenterElement.appendChild(//from  w w w  . j  av a2  s . co  m
            XmlUtility.createSimpleTextElement(nameSpace, documentParent, "hasName", dataCenter.getHasName()));
    dataCenterElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent, "hasIdentifier",
            dataCenter.getHasIdentifier()));

    return dataCenterElement;
}

From source file:org.cloudsimulator.xml.rdf.xmlrdfconverter.ExternalStorageToXmlRdf.java

License:Open Source License

public static Element createExternalStorageElement(final Namespace nameSpace, final Document documentParent,
        final ExternalStorage externalStorage) {

    Element externalStorageElement = documentParent.createElementNS(nameSpace.getURI(),
            nameSpace.getPrefix() + ":ExternalStorage");
    externalStorageElement.setAttributeNS(NameSpaceRepository.RDF.getURI(),
            NameSpaceRepository.RDF.getPrefix() + ":about", externalStorage.getUri());
    externalStorageElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent, "hasName",
            externalStorage.getHasName()));
    externalStorageElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent,
            "hasIdentifier", externalStorage.getHasIdentifier()));
    externalStorageElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent,
            "hasModelName", externalStorage.getHasModelName()));

    boolean firstSharedStorageVolume = true;
    Element hasPartElement = documentParent.createElementNS(nameSpace.getURI(),
            nameSpace.getPrefix() + ":hasPart");
    for (SharedStorageVolume sharedStorageVolume : externalStorage.getSharedStorageVolumeList()) {
        if (sharedStorageVolume != null) {
            if (firstSharedStorageVolume) {
                externalStorageElement.appendChild(hasPartElement);
                firstSharedStorageVolume = false;
            }//from  ww  w .  j  a va 2  s.c o m
            Element sharedStorageVolumeElement = SharedStorageVolumeToXmlRdf
                    .createSharedStorageVolumeElement(nameSpace, documentParent, sharedStorageVolume);
            hasPartElement.appendChild(sharedStorageVolumeElement);
        }
    }

    boolean firstNetworkAdapter = true;
    Element hasNetworkAdapterElement = documentParent.createElementNS(nameSpace.getURI(),
            nameSpace.getPrefix() + ":hasNetworkAdapter");
    for (NetworkAdapter networkAdapter : externalStorage.getHasNetworkAdapterList()) {
        if (networkAdapter != null) {
            if (firstNetworkAdapter) {
                externalStorageElement.appendChild(hasNetworkAdapterElement);
                firstNetworkAdapter = false;
            }
            hasNetworkAdapterElement.appendChild(NetworkAdapterToXmlRdf.createNetworkAdapterElement(nameSpace,
                    documentParent, networkAdapter));
        }
    }

    externalStorageElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent,
            "hasMonitorIPAddress", externalStorage.getHasMonitorIPAddress()));

    boolean firstMonitorInfo = true;
    Element hasMonitorInfoElement = documentParent.createElementNS(nameSpace.getURI(),
            nameSpace.getPrefix() + ":hasMonitorInfo");
    for (MonitorInfo monitorInfo : externalStorage.getHasMonitorInfoList()) {
        if (monitorInfo != null) {
            if (firstMonitorInfo) {
                externalStorageElement.appendChild(hasMonitorInfoElement);
                firstMonitorInfo = false;
            }
            hasMonitorInfoElement.appendChild(
                    MonitorInfoToXmlRdf.createMonitorInfoElement(nameSpace, documentParent, monitorInfo));
        }
    }

    externalStorageElement.appendChild(XmlUtility.createSimpleTextElement(nameSpace, documentParent,
            "hasMonitorState", externalStorage.getHasMonitorState()));

    return externalStorageElement;
}