Example usage for javax.xml.namespace QName getLocalPart

List of usage examples for javax.xml.namespace QName getLocalPart

Introduction

In this page you can find the example usage for javax.xml.namespace QName getLocalPart.

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

From source file:com.collabnet.ccf.teamforge.TFWriter.java

private PlanningFolderDO updatePlanningFolder(GenericArtifact ga, String project, Connection connection)
        throws RemoteException, PlanningFolderRuleViolationException {

    String id = ga.getTargetArtifactId();

    String targetSystemTimezone = ga.getTargetSystemTimezone();

    GenericArtifactField description = GenericArtifactHelper
            .getMandatoryGAField(TFArtifactMetaData.TFFields.description.getFieldName(), ga);

    GenericArtifactField title = GenericArtifactHelper
            .getMandatoryGAField(TFArtifactMetaData.TFFields.title.getFieldName(), ga);

    GenericArtifactField statusField = null;
    GenericArtifactField releaseIdField = null;
    GenericArtifactField capacityField = null;
    GenericArtifactField pointsCapacityField = null;
    GenericArtifactField trackerUnitIdField = null;

    if (connection.supports54()) {
        statusField = GenericArtifactHelper
                .getMandatoryGAField(TFArtifactMetaData.TFFields.status.getFieldName(), ga);
        releaseIdField = GenericArtifactHelper
                .getMandatoryGAField(TFArtifactMetaData.TFFields.releaseId.getFieldName(), ga);
        capacityField = GenericArtifactHelper
                .getMandatoryGAField(TFArtifactMetaData.TFFields.capacity.getFieldName(), ga);
    }/*from  ww w .  j ava 2 s  .  c  om*/

    if (connection.supports62()) {
        trackerUnitIdField = GenericArtifactHelper
                .getMandatoryGAField(TFArtifactMetaData.TFFields.trackerUnitId.getFieldName(), ga);
    }

    if (connection.supports63()) {
        pointsCapacityField = GenericArtifactHelper
                .getMandatoryGAField(TFArtifactMetaData.TFFields.pointsCapacity.getFieldName(), ga);
    }

    GenericArtifactField startDateField = GenericArtifactHelper
            .getMandatoryGAField(TFArtifactMetaData.TFFields.startDate.getFieldName(), ga);

    if (startDateField != null && startDateField.getFieldValueHasChanged()) {
        GregorianCalendar gc = (GregorianCalendar) startDateField.getFieldValue();
        if (gc != null) {
            Date dateValue = gc.getTime();
            if (DateUtil.isAbsoluteDateInTimezone(dateValue, "GMT")) {
                startDateField.setFieldValue(
                        DateUtil.convertGMTToTimezoneAbsoluteDate(dateValue, targetSystemTimezone));
            } else {
                startDateField.setFieldValue(dateValue);
            }
        }
    }

    GenericArtifactField endDateField = GenericArtifactHelper
            .getMandatoryGAField(TFArtifactMetaData.TFFields.endDate.getFieldName(), ga);

    if (endDateField != null && endDateField.getFieldValueHasChanged()) {
        GregorianCalendar gc = (GregorianCalendar) endDateField.getFieldValue();
        if (gc != null) {
            Date dateValue = gc.getTime();
            if (DateUtil.isAbsoluteDateInTimezone(dateValue, "GMT")) {
                endDateField.setFieldValue(
                        DateUtil.convertGMTToTimezoneAbsoluteDate(dateValue, targetSystemTimezone));
            } else {
                endDateField.setFieldValue(dateValue);
            }
        }
    }

    boolean planningFolderNotUpdated = true;
    PlanningFolderDO planningFolder = null;
    while (planningFolderNotUpdated) {
        try {
            planningFolderNotUpdated = false;
            planningFolder = connection.getPlanningClient().getPlanningFolderData(id);

            // do conflict resolution
            if (!AbstractWriter.handleConflicts(planningFolder.getVersion(), ga)) {
                return null;
            }

            if (title != null && title.getFieldValueHasChanged()) {
                planningFolder.setTitle((String) title.getFieldValue());
            }
            if (description != null && description.getFieldValueHasChanged()) {
                planningFolder.setDescription((String) description.getFieldValue());
            }
            if (startDateField != null && startDateField.getFieldValueHasChanged()) {
                planningFolder.setStartDate((Date) startDateField.getFieldValue());
            }
            if (endDateField != null && endDateField.getFieldValueHasChanged()) {
                planningFolder.setEndDate((Date) endDateField.getFieldValue());
            }

            if (statusField != null && statusField.getFieldValueHasChanged()) {
                planningFolder.setStatus((String) statusField.getFieldValue());
            }

            if (releaseIdField != null && releaseIdField.getFieldValueHasChanged()) {
                String releaseId = (String) releaseIdField.getFieldValue();
                if (translateTechnicalReleaseIds) {
                    releaseId = TFTrackerHandler.convertReleaseIdForProject(connection, releaseId, project,
                            isReleaseIdFieldsContainFileReleasePackageName()
                                    ? getPackageReleaseSeparatorString()
                                    : null);
                }

                planningFolder.setReleaseId(releaseId);
            }

            if (capacityField != null && capacityField.getFieldValueHasChanged()) {
                Object fieldValueObj = capacityField.getFieldValue();
                int fieldValue = 0;
                if (fieldValueObj instanceof String) {
                    String fieldValueString = (String) fieldValueObj;
                    try {
                        fieldValue = Integer.parseInt(fieldValueString);
                    } catch (NumberFormatException e) {
                        throw new CCFRuntimeException(
                                "Could not parse value of mandatory field capacity: " + e.getMessage(), e);
                    }
                } else if (fieldValueObj instanceof Integer) {
                    fieldValue = ((Integer) fieldValueObj).intValue();
                }
                planningFolder.setCapacity(fieldValue);

            }

            if (pointsCapacityField != null && pointsCapacityField.getFieldValueHasChanged()) {
                Object fieldValueObj = pointsCapacityField.getFieldValue();
                int fieldValue = 0;
                if (fieldValueObj instanceof String) {
                    String fieldValueString = (String) fieldValueObj;
                    try {
                        fieldValue = Integer.parseInt(fieldValueString);
                    } catch (NumberFormatException e) {
                        throw new CCFRuntimeException(
                                "Could not parse value of mandatory field points capacity: " + e.getMessage(),
                                e);
                    }
                } else if (fieldValueObj instanceof Integer) {
                    fieldValue = ((Integer) fieldValueObj).intValue();
                }
                planningFolder.setPointsCapacity(fieldValue);

                if (trackerUnitIdField != null && trackerUnitIdField.getFieldValueHasChanged()) {
                    String trackerUnitId = (String) trackerUnitIdField.getFieldValue();
                    String trackerUnitIdValue = !StringUtils.isEmpty(trackerUnitId) ? trackerUnitId : "Hours";
                    trackerUnitId = TFTrackerHandler.getTrackerUnitId(connection, trackerUnitIdValue, project);
                    planningFolder.setTrackerUnitId(trackerUnitId);
                }

            }
            connection.getPlanningClient().setPlanningFolderData(planningFolder);
        } catch (AxisFault e) {
            javax.xml.namespace.QName faultCode = e.getFaultCode();
            if (!faultCode.getLocalPart().equals("VersionMismatchFault")) {
                throw e;
            }
            logConflictResolutor.warn("Stale update for TF planning folder " + id + " in project " + project
                    + ". Trying again ...", e);
            planningFolderNotUpdated = true;
        }
    }

    planningFolder = connection.getPlanningClient().getPlanningFolderData(id);

    // now we have to cope with moving planning folders around
    String parentArtifactId = ga.getDepParentTargetArtifactId();
    // first of all, if parent is unknown or null, we do not change anything
    if (parentArtifactId != null && !parentArtifactId.equals(GenericArtifact.VALUE_UNKNOWN)) {
        // check for the special case this is a top level PF
        if (parentArtifactId.equals(GenericArtifact.VALUE_NONE)) {
            // check whether this is already a top level planning folder
            if (!planningFolder.getParentFolderId().startsWith("PlanningApp")) {
                // move to top
                connection.getPlanningClient().movePlanningFolder(id, project);
                planningFolder = connection.getPlanningClient().getPlanningFolderData(id);
            }
        } else {
            // check whether correct parent is already assigned
            if (!parentArtifactId.equals(planningFolder.getParentFolderId())) {
                connection.getPlanningClient().movePlanningFolder(id, parentArtifactId);
                planningFolder = connection.getPlanningClient().getPlanningFolderData(id);
            }
        }
    }
    log.info("Planning folder updated. TF Id: " + planningFolder.getId() + " in project " + project
            + " other system id: " + ga.getSourceArtifactId() + " in repository: "
            + ga.getSourceRepositoryId());
    return planningFolder;
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistryImpl.java

@Override
public ItemDefinition resolveGlobalItemDefinition(QName itemName,
        @Nullable ComplexTypeDefinition complexTypeDefinition) throws SchemaException {
    if (QNameUtil.noNamespace(itemName)) {
        if (complexTypeDefinition != null && complexTypeDefinition.getDefaultNamespace() != null) {
            itemName = new QName(complexTypeDefinition.getDefaultNamespace(), itemName.getLocalPart());
        } else {//from w  w w .  ja v  a  2 s . c  o m
            List<String> ignoredNamespaces = complexTypeDefinition != null
                    ? complexTypeDefinition.getIgnoredNamespaces()
                    : null;
            return resolveGlobalItemDefinitionWithoutNamespace(itemName.getLocalPart(), ItemDefinition.class,
                    true, ignoredNamespaces);
        }
    }
    PrismSchema schema = findSchemaByNamespace(itemName.getNamespaceURI());
    if (schema == null) {
        return null;
    }
    return schema.findItemDefinitionByElementName(itemName, ItemDefinition.class);
}

From source file:com.evolveum.midpoint.schema.xjc.schema.SchemaProcessor.java

private JFieldVar getReferencedField(JFieldVar field, ClassOutline classOutline) {
    QName qname = getFieldReferenceUseAnnotationQName(field, classOutline);
    CPropertyInfo propertyInfo = classOutline.target.getProperty(qname.getLocalPart());
    if (propertyInfo == null) {
        throw new IllegalArgumentException(
                "No property " + qname.getLocalPart() + " in " + classOutline.target);
    }/* w ww  . ja  v  a  2  s  .c o  m*/
    return classOutline.implClass.fields().get(propertyInfo.getName(false));
}

From source file:gov.nih.nci.cacis.common.util.ExtractSchematron.java

private void postprocessDatatypeExtensions() {
    // first we have to do a pass to deal with a weird bug in xerces: if a type is used
    // before its parent type, its annotations are also placed on its parent type. so
    // do a pass to remove children's rules from their parents. we rely on uniqueness of
    // rule ids here
    for (final QName type : this.datatypeUsages.keySet()) {
        final TypeUsage typeUsage = this.datatypeUsages.get(type); // NOPMD
        for (QName currentType = this.datatypeExtensions
                .get(type); currentType != null; currentType = this.datatypeExtensions.get(currentType)) {
            this.datatypeUsages.get(currentType).getRuleIds().removeAll(typeUsage.getRuleIds());
        }/*from  www  .j a  v  a  2s . c  o m*/
    }

    // now go ahead and add in the rules of parents, and the contexts of parents (with xsi:type="child type"), to
    // children
    // because we are using sets, we don't care about the order here which would
    // otherwise cause rules from subtypes to get added to supertypes multiple times
    for (final QName type : this.datatypeUsages.keySet()) {
        final TypeUsage typeUsage = this.datatypeUsages.get(type); // NOPMD
        for (QName parentType = this.datatypeExtensions
                .get(type); parentType != null; parentType = this.datatypeExtensions.get(parentType)) {
            final TypeUsage parentUsage = this.datatypeUsages.get(parentType);
            typeUsage.getRuleIds().addAll(parentUsage.getRuleIds());
            for (final String context : parentUsage.getContexts()) {
                typeUsage.getContexts().add(addXsiType(context, type.getLocalPart()));
            }
        }
    }
}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

private org.dom4j.QName createDom4jQName(QName qname, XmlSchemaForm form) {
    org.dom4j.QName dom4jQname = null;

    if (qname != null) {
        String nsUri = qname.getNamespaceURI();
        Namespace ns = null;/*  www .ja v a  2  s .  c o  m*/
        if (StringUtils.isNotEmpty(nsUri)) {
            if (form == XmlSchemaForm.QUALIFIED) {
                String prefix = nsMap.getPrefix(nsUri);

                if (StringUtils.isEmpty(prefix)) {
                    prefix = DEFAULT_PREFIX + prefixCounter++;
                    nsMap.add(prefix, nsUri);
                }

                ns = new Namespace(prefix, nsUri);
            }
        }
        dom4jQname = new org.dom4j.QName(qname.getLocalPart(), ns);
    }
    return dom4jQname;
}

From source file:com.evolveum.midpoint.schema.xjc.schema.SchemaProcessor.java

private JFieldVar createQNameDefinition(Outline outline, JDefinedClass definedClass, String fieldName,
        JFieldVar namespaceField, QName reference) {
    JClass schemaClass = outline.getModel().codeModel._getClass(StepSchemaConstants.CLASS_NAME);

    JInvocation invocation = JExpr._new(CLASS_MAP.get(QName.class));
    invocation.arg(schemaClass.staticRef(namespaceField));
    invocation.arg(reference.getLocalPart());

    int psf = JMod.PUBLIC | JMod.STATIC | JMod.FINAL;
    return definedClass.field(psf, QName.class, fieldName, invocation);
}

From source file:com.emental.mindraider.ui.graph.spiders.SpidersGraph.java

/**
 * As subject is used selected node. TODO FUUUUJ - forget about QNames and
 * change to URNs!/*  w w w . j ava 2  s.c o m*/
 *
 * @param predicate
 *            the predicate
 * @param object
 *            the object
 * @param literal
 *            the literal flag
 * @return the Statement
 */
public Statement createStatement(QName predicate, QName object, boolean literal) {
    Resource subject = null;
    ConceptResource conceptResource = OutlineJPanel.getInstance().conceptJPanel.getConceptResource();
    if (conceptResource == null) {
        JOptionPane.showMessageDialog(MindRaider.mainJFrame, "No not selected - RDF triplet cannot be created!",
                "Triplet Creation Error", JOptionPane.ERROR_MESSAGE);
    } else {
        subject = rdfModel.getResource(conceptResource.getUri());
        if (subject == null) {
            JOptionPane.showMessageDialog(MindRaider.mainJFrame,
                    "Unable to find RDF node with ID '" + conceptResource.getUri() + "'",
                    "Triplet Creation Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    Statement statement = rdfModel.createStatement(subject,
            (predicate.getNamespaceURI() == null ? MindRaiderConstants.MR_RDF_NS : predicate.getNamespaceURI())
                    + predicate.getLocalPart(),
            (object.getNamespaceURI() == null ? object.getLocalPart()
                    : object.getNamespaceURI() + object.getLocalPart()),
            literal);

    save();
    renderModel();

    return statement;
}

From source file:com.evolveum.midpoint.schema.xjc.schema.SchemaProcessor.java

/**
 * Marks ObjectFactory.createXYZ methods for elements with a:rawType annotation as @Raw.
 *//*from w  w  w . j a  v  a  2s . c  o  m*/
private void updateObjectFactoryElements(Outline outline) {
    XSSchemaSet schemaSet = outline.getModel().schemaComponent;
    for (CElementInfo elementInfo : outline.getModel().getAllElements()) {
        QName name = elementInfo.getElementName();
        XSComponent elementDecl;
        if (elementInfo.getSchemaComponent() != null) { // it's strange but elements seem not to have this filled-in...
            elementDecl = elementInfo.getSchemaComponent();
        } else {
            elementDecl = schemaSet.getElementDecl(name.getNamespaceURI(), name.getLocalPart());
        }
        boolean isRaw = hasAnnotation(elementDecl, A_RAW_TYPE);
        if (isRaw) {
            System.out.println("*** Raw element found: " + elementInfo.getElementName());
            JDefinedClass objectFactory = outline.getPackageContext(elementInfo._package()).objectFactory();
            boolean methodFound = false; // finding method corresponding to the given element
            for (JMethod method : objectFactory.methods()) {
                for (JAnnotationUse annotationUse : method.annotations()) {
                    if (XmlElementDecl.class.getName().equals(annotationUse.getAnnotationClass().fullName())) {
                        // ugly method of finding the string value of the annotation members (couldn't find any better)
                        JAnnotationValue namespaceValue = annotationUse.getAnnotationMembers().get("namespace");
                        StringWriter namespaceWriter = new StringWriter();
                        JFormatter namespaceFormatter = new JFormatter(namespaceWriter);
                        namespaceValue.generate(namespaceFormatter);

                        JAnnotationValue nameValue = annotationUse.getAnnotationMembers().get("name");
                        StringWriter nameWriter = new StringWriter();
                        JFormatter nameFormatter = new JFormatter(nameWriter);
                        nameValue.generate(nameFormatter);

                        if (("\"" + name.getNamespaceURI() + "\"").equals(namespaceWriter.toString())
                                && ("\"" + name.getLocalPart() + "\"").equals(nameWriter.toString())) {
                            System.out.println("*** Annotating method as @Raw: " + method.name());
                            method.annotate(Raw.class);
                            methodFound = true;
                            break;
                        }
                    }
                }
            }
            if (!methodFound) {
                throw new IllegalStateException("No factory method found for element " + name);
            }
        }
    }
}

From source file:com.evolveum.midpoint.prism.PrismContainerValue.java

private <IV extends PrismValue, ID extends ItemDefinition, I extends Item<IV, ID>> I createSubItem(QName name,
        Class<I> type, ID itemDefinition) throws SchemaException {
    // the item with specified name does not exist, create it now
    I newItem = null;//from  w w w  . j  av a  2s .  c  o m

    if (itemDefinition == null && getActualDefinition() != null) {
        itemDefinition = determineItemDefinition(name, getActualDefinition());
        if (itemDefinition == null) {
            throw new SchemaException("No definition for item " + name + " in " + getParent());
        }
    }

    if (itemDefinition != null) {
        if (StringUtils.isNotBlank(name.getNamespaceURI())) {
            newItem = (I) itemDefinition.instantiate(name);
        } else {
            QName computed = new QName(itemDefinition.getNamespace(), name.getLocalPart());
            newItem = (I) itemDefinition.instantiate(computed);
        }
        if (newItem instanceof PrismObject) {
            throw new IllegalStateException(
                    "PrismObject instantiated as a subItem in " + this + " from definition " + itemDefinition);
        }
    } else {
        newItem = Item.createNewDefinitionlessItem(name, type, prismContext);
        if (newItem instanceof PrismObject) {
            throw new IllegalStateException("PrismObject instantiated as a subItem in " + this
                    + " as definitionless instance of class " + type);
        }
    }

    if (type.isAssignableFrom(newItem.getClass())) {
        add(newItem);
        return newItem;
    } else {
        throw new IllegalStateException(
                "The " + type.getSimpleName() + " cannot be created because the item should be of type "
                        + newItem.getClass().getSimpleName() + " (" + newItem.getElementName() + ")");
    }
}

From source file:com.evolveum.midpoint.testing.model.client.sample.AbstractTestForExchangeConnector.java

protected ShadowType getShadowByName(String resourceOid, QName objectClass, String name)
        throws JAXBException, SAXException, IOException, FaultMessage {
    // WARNING: in a real case make sure that the username is properly escaped before putting it in XML
    SearchFilterType filter = ModelClientUtil.parseSearchFilterType(
            "                        <q:and xmlns:q='http://prism.evolveum.com/xml/ns/public/query-3' xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'>\n"
                    + "                            <q:ref>\n"
                    + "                                <q:path>resourceRef</q:path>\n"
                    + "                                <q:value>\n"
                    + "                                    <oid>" + resourceOid + "</oid>\n"
                    + "                                    <type>ResourceType</type>\n"
                    + "                                </q:value>\n" + "                            </q:ref>\n"
                    + "                            <q:equal>\n"
                    + "                                <q:path>objectClass</q:path>\n"
                    + "                                <q:value xmlns:a=\"" + objectClass.getNamespaceURI()
                    + "\">a:" + objectClass.getLocalPart() + "</q:value>\n"
                    + "                            </q:equal>\n" + "                            <q:equal>\n"
                    + "                                <q:path>attributes/name</q:path>\n"
                    + "                                <q:value>" + name + "</q:value>\n"
                    + "                            </q:equal>\n" + "                        </q:and>\n");
    QueryType query = new QueryType();
    query.setFilter(filter);//from w ww .j  a  va 2  s . c  om
    SelectorQualifiedGetOptionsType options = new SelectorQualifiedGetOptionsType();
    Holder<ObjectListType> objectListHolder = new Holder<>();
    Holder<OperationResultType> resultHolder = new Holder<>();

    modelPort.searchObjects(ModelClientUtil.getTypeQName(ShadowType.class), query, options, objectListHolder,
            resultHolder);

    ObjectListType objectList = objectListHolder.value;
    List<ObjectType> objects = objectList.getObject();
    if (objects.isEmpty()) {
        return null;
    }
    if (objects.size() == 1) {
        return (ShadowType) objects.get(0);
    }
    throw new IllegalStateException("Expected to find a single shadow with name '" + name + "' but found "
            + objects.size() + " ones instead");
}