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.evolveum.midpoint.prism.PrismReferenceValue.java

@Override
public int hashCode() {
    final int prime = 31;
    int result = super.hashCode();
    result = prime * result + ((oid == null) ? 0 : oid.hashCode());
    QName normalizedRelation = normalizedRelation(relation, false);
    if (normalizedRelation != null) {
        // Take just the local part to avoid problems with incomplete namespaces
        String relationLocal = normalizedRelation.getLocalPart();
        if (relationLocal != null) {
            result = prime * result + relationLocal.hashCode();
        }//from   w w  w .j a  v a 2s .com
    }
    return result;
}

From source file:com.collabnet.ccf.pi.sfee.v44.SFEEWriter.java

@Override
public boolean handleException(Throwable cause, ConnectionManager<Connection> connectionManager, Document ga) {
    if (cause == null)
        return false;
    if ((cause instanceof java.net.SocketException || cause instanceof java.net.UnknownHostException)
            && connectionManager.isEnableRetryAfterNetworkTimeout()) {
        return true;
    } else if (cause instanceof ConnectionException && connectionManager.isEnableRetryAfterNetworkTimeout()) {
        return true;
    } else if (cause instanceof AxisFault) {
        QName faultCode = ((AxisFault) cause).getFaultCode();
        if (faultCode.getLocalPart().equals("InvalidSessionFault")
                && connectionManager.isEnableReloginAfterSessionTimeout()) {
            return true;
        }/*w ww .j  a  v  a2s. co m*/
    } else if (cause instanceof RemoteException) {
        Throwable innerCause = cause.getCause();
        return handleException(innerCause, connectionManager, ga);
    } else if (cause instanceof CCFRuntimeException) {
        Throwable innerCause = cause.getCause();
        return handleException(innerCause, connectionManager, ga);
    }
    return false;
}

From source file:com.evolveum.midpoint.web.page.admin.server.PageTaskAdd.java

private TaskType createTask(TaskAddDto dto) throws SchemaException {
    TaskType task = new TaskType();
    MidPointPrincipal owner = SecurityUtils.getPrincipalUser();

    ObjectReferenceType ownerRef = new ObjectReferenceType();
    ownerRef.setOid(owner.getOid());/*from w ww.  j a  va2  s. co m*/
    ownerRef.setType(owner.getUser().COMPLEX_TYPE);
    task.setOwnerRef(ownerRef);

    task.setCategory(dto.getCategory());
    String handlerUri = getTaskManager().getHandlerUriForCategory(dto.getCategory());
    if (handlerUri == null) {
        throw new SystemException("Cannot determine task handler URI for category " + dto.getCategory());
    }
    task.setHandlerUri(handlerUri);

    ObjectReferenceType objectRef;
    if (dto.getResource() != null) {
        objectRef = new ObjectReferenceType();
        objectRef.setOid(dto.getResource().getOid());
        objectRef.setType(ResourceType.COMPLEX_TYPE);
        task.setObjectRef(objectRef);
    }

    task.setName(WebMiscUtil.createPolyFromOrigString(dto.getName()));

    task.setRecurrence(dto.getReccuring() ? TaskRecurrenceType.RECURRING : TaskRecurrenceType.SINGLE);
    task.setBinding(dto.getBound() ? TaskBindingType.TIGHT : TaskBindingType.LOOSE);

    ScheduleType schedule = new ScheduleType();
    schedule.setInterval(dto.getInterval());
    schedule.setCronLikePattern(dto.getCron());
    schedule.setEarliestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartBefore()));
    schedule.setLatestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartAfter()));
    schedule.setMisfireAction(dto.getMisfireAction());
    task.setSchedule(schedule);

    if (dto.getSuspendedState()) {
        task.setExecutionStatus(TaskExecutionStatusType.SUSPENDED);
    } else {
        task.setExecutionStatus(TaskExecutionStatusType.RUNNABLE);
    }

    if (dto.getThreadStop() != null) {
        task.setThreadStopAction(dto.getThreadStop());
    } else {
        // fill-in default
        if (dto.getRunUntilNodeDown() == true) {
            task.setThreadStopAction(ThreadStopActionType.CLOSE);
        } else {
            task.setThreadStopAction(ThreadStopActionType.RESTART);
        }
    }

    if (dto.isDryRun()) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_DRY_RUN);
        PrismProperty dryRun = prismTask.findOrCreateProperty(path);

        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
        dryRun.setDefinition(def);
        dryRun.setRealValue(true);
    }

    if (dto.getFocusType() != null) {

        PrismObject<TaskType> prismTask = task.asPrismObject();

        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECT_TYPE);
        PrismProperty focusType = prismTask.findOrCreateProperty(path);
        focusType.setRealValue(dto.getFocusType());

    }

    if (dto.getKind() != null) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND);
        PrismProperty kind = prismTask.findOrCreateProperty(path);

        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_KIND);
        kind.setDefinition(def);
        kind.setRealValue(dto.getKind());
    }

    if (dto.getIntent() != null && StringUtils.isNotEmpty(dto.getIntent())) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT);
        PrismProperty intent = prismTask.findOrCreateProperty(path);

        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_INTENT);
        intent.setDefinition(def);
        intent.setRealValue(dto.getIntent());
    }

    if (dto.getObjectClass() != null && StringUtils.isNotEmpty(dto.getObjectClass())) {
        PrismObject<TaskType> prismTask = task.asPrismObject();
        ItemPath path = new ItemPath(TaskType.F_EXTENSION, SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
        PrismProperty objectClassProperty = prismTask.findOrCreateProperty(path);

        QName objectClass = null;
        for (QName q : model.getObject().getObjectClassList()) {
            if (q.getLocalPart().equals(dto.getObjectClass())) {
                objectClass = q;
            }
        }

        SchemaRegistry registry = getPrismContext().getSchemaRegistry();
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
        objectClassProperty.setDefinition(def);
        objectClassProperty.setRealValue(objectClass);
    }

    return task;
}

From source file:com.evolveum.midpoint.model.common.expression.script.xpath.ReflectionXPathFunctionResolver.java

@Override
public XPathFunction resolveFunction(QName functionQName, int arity) {
    boolean enableDebug = false;
    String namespace = functionQName.getNamespaceURI();
    if (StringUtils.isEmpty(namespace)) {
        namespace = MidPointConstants.NS_FUNC_BASIC;
        enableDebug = true;//w w w  . j a  v  a  2 s . c o  m
    } else if (namespace.equals(MidPointConstants.NS_FUNC_BASIC)) {
        enableDebug = true;
    }

    FunctionLibrary lib = findLibrary(namespace);
    if (lib == null) {
        LOGGER.trace("Unknown namespace for function {} function with {} arguments", functionQName, arity);
        return null;
    }

    Object functionObject = null;
    if (lib.getXmlFunctions() != null) {
        functionObject = lib.getXmlFunctions();
    } else {
        functionObject = lib.getGenericFunctions();
    }

    String functionName = functionQName.getLocalPart();

    LOGGER.trace("Resolving to {} function with {} arguments", functionName, arity);
    ReflectionXPathFunctionWrapper xPathFunction = new ReflectionXPathFunctionWrapper(functionObject,
            functionName, arity, enableDebug);
    return xPathFunction;
}

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

private void setAttribute(Element element, QName attr, QName attrValue) {
    if (attributeQualified) {
        DOMUtil.setQNameAttribute(element, attr, attrValue, rootXsdElement);
        addToImport(attr.getNamespaceURI());
    } else {/*from  ww w . j av  a2s.c o m*/
        DOMUtil.setQNameAttribute(element, attr.getLocalPart(), attrValue, rootXsdElement);
    }
}

From source file:org.apache.juddi.v3.client.mapping.wadl.WADL2UDDI.java

/**
 * Creates a UDDI Business Service./* w  ww.  j av  a2s. c  om*/
 *
 * @param serviceQName This must be specified to identify the namespace of
 * the service, which is used to set the service uddi key
 * @param wadlDefinition
 * @return BusinessService
 * @throws MalformedURLException
 */
public BusinessService createBusinessService(QName serviceQName, Application wadlDefinition)
        throws MalformedURLException {

    log.debug("Constructing Service UDDI Information for " + serviceQName);
    BusinessService service = new BusinessService();
    // BusinessKey
    service.setBusinessKey(businessKey);
    // ServiceKey
    service.setServiceKey(UDDIKeyConvention.getServiceKey(properties, serviceQName.getLocalPart()));
    // Description
    String serviceDescription = properties.getProperty(Property.SERVICE_DESCRIPTION,
            Property.DEFAULT_SERVICE_DESCRIPTION);
    // Override with the service description from the WADL if present
    boolean lengthwarn = false;
    if (!wadlDefinition.getDoc().isEmpty()) {

        for (int i = 0; i < wadlDefinition.getDoc().size(); i++) {
            String locallang = lang;
            if (wadlDefinition.getDoc().get(i).getLang() != null) {
                locallang = (wadlDefinition.getDoc().get(i).getLang());
            }
            if (locallang.length() > UDDIConstants.MAX_xml_lang_length) {
                lengthwarn = true;
                locallang = (locallang.substring(0, UDDIConstants.MAX_xml_lang_length - 1));
            }

            StringBuilder sb = new StringBuilder();
            sb.append(wadlDefinition.getDoc().get(i).getTitle()).append(" ");
            sb.append(ContentToString(wadlDefinition.getDoc().get(i).getContent()));

            service.getDescription().addAll(Common2UDDI.mapDescription(sb.toString(), locallang));

        }
    } else {
        service.getDescription().addAll(Common2UDDI.mapDescription(serviceDescription, lang));
    }

    // Service name
    Name sName = new Name();
    sName.setLang(lang);
    if (!wadlDefinition.getDoc().isEmpty()) {
        sName.setValue(wadlDefinition.getDoc().get(0).getTitle());
    }
    if (sName.getValue() == null) {
        sName.setValue(serviceQName.getLocalPart());
    }
    service.getName().add(sName);

    CategoryBag categoryBag = new CategoryBag();

    String namespace = serviceQName.getNamespaceURI();
    if (namespace != null && namespace.length() != 0) {
        KeyedReference namespaceReference = newKeyedReference("uddi:uddi.org:xml:namespace",
                "uddi-org:xml:namespace", namespace);
        categoryBag.getKeyedReference().add(namespaceReference);
    }

    KeyedReference serviceReference = newKeyedReference("uddi:uddi.org:wadl:types", "uddi-org:wadl:types",
            "service");
    categoryBag.getKeyedReference().add(serviceReference);

    KeyedReference localNameReference = newKeyedReference("uddi:uddi.org:xml:localname",
            "uddi-org:xml:localName", serviceQName.getLocalPart());
    categoryBag.getKeyedReference().add(localNameReference);

    service.setCategoryBag(categoryBag);

    for (int i = 0; i < wadlDefinition.getResources().size(); i++) {
        BindingTemplate bindingTemplate = createWADLBinding(serviceQName,
                getDocTitle(wadlDefinition.getResources().get(i).getDoc()),
                new URL(wadlDefinition.getResources().get(i).getBase()), wadlDefinition.getResources().get(i));
        service.setBindingTemplates(new BindingTemplates());
        service.getBindingTemplates().getBindingTemplate().add(bindingTemplate);
    }

    if (lengthwarn) {
        log.warn(
                "Some object descriptions are longer than the maximum allowed by UDDI and have been truncated.");
    }
    return service;
}

From source file:com.twinsoft.convertigo.beans.core.Step.java

public QName getSimpleTypeAffectation() {
    QName qName = getXmlSimpleTypeAffectation().getQName();
    if (qName.getLocalPart().length() == 0) {
        qName = Constants.XSD_STRING;//w  w  w . ja v a  2  s .  c om
    }
    return qName;
}

From source file:com.collabnet.ccf.pi.sfee.v44.SFEETrackerHandler.java

/**
 * Updates the artifact if conflict resolution priority allows it
 * /*  w ww . java  2  s . c  o  m*/
 * @param ga
 *            generic artifact passed to the update method
 * @param sessionId
 * @param trackerId
 * @param description
 * @param category
 * @param group
 * @param status
 * @param statusClass
 * @param customer
 * @param priority
 * @param estimatedHours
 * @param actualHours
 * @param closeDate
 * @param assignedTo
 * @param reportedReleaseId
 * @param resolvedReleaseId
 * @param flexFieldNames
 * @param flexFieldValues
 * @param flexFieldTypes
 * @param flexFieldPreserve
 * @param title
 * @param Id
 * @param comments
 * @param conflictResolutionPriority
 * @return updated artifact or null if conflict resolution has decided not
 *         to update the artifact
 * @throws RemoteException
 */
public ArtifactSoapDO updateArtifact(GenericArtifact ga, String sessionId, GenericArtifactField trackerId,
        GenericArtifactField description, GenericArtifactField category, GenericArtifactField group,
        GenericArtifactField status, GenericArtifactField statusClass, GenericArtifactField customer,
        GenericArtifactField priority, GenericArtifactField estimatedHours, GenericArtifactField actualHours,
        GenericArtifactField closeDate, GenericArtifactField assignedTo, GenericArtifactField reportedReleaseId,
        GenericArtifactField resolvedReleaseId, List<String> flexFieldNames, List<Object> flexFieldValues,
        List<String> flexFieldTypes, Set<String> overriddenFlexFields, GenericArtifactField title, String Id,
        String[] comments, boolean translateTechnicalReleaseIds) throws RemoteException {

    boolean mainArtifactNotUpdated = true;
    ArtifactSoapDO artifactData = null;
    while (mainArtifactNotUpdated) {
        try {
            mainArtifactNotUpdated = false;
            artifactData = mTrackerApp.getArtifactData(sessionId, Id);
            // do conflict resolution
            if (!AbstractWriter.handleConflicts(artifactData.getVersion(), ga)) {
                return null;
            }

            // here we store the values which will be really sent
            ArrayList<String> finalFlexFieldNames = new ArrayList<String>();
            ArrayList<String> finalFlexFieldTypes = new ArrayList<String>();
            ArrayList<Object> finalFlexFieldValues = new ArrayList<Object>();

            SoapFieldValues currentFlexFields = artifactData.getFlexFields();
            String[] currentFlexFieldNames = currentFlexFields.getNames();
            Object[] currentFlexFieldValues = currentFlexFields.getValues();
            String[] currentFlexFieldTypes = currentFlexFields.getTypes();

            // first we filter out all current flex fields that should be
            // overridden
            for (int i = 0; i < currentFlexFieldNames.length; ++i) {
                if (!overriddenFlexFields.contains(currentFlexFieldNames[i])) {
                    finalFlexFieldNames.add(currentFlexFieldNames[i]);
                    finalFlexFieldTypes.add(currentFlexFieldTypes[i]);
                    finalFlexFieldValues.add(currentFlexFieldValues[i]);
                }
            }

            // now we have to add all anticipated flex fields
            finalFlexFieldNames.addAll(flexFieldNames);
            finalFlexFieldValues.addAll(flexFieldValues);
            finalFlexFieldTypes.addAll(flexFieldTypes);

            SoapFieldValues flexFields = new SoapFieldValues();
            flexFields.setNames(finalFlexFieldNames.toArray(new String[0]));
            flexFields.setValues(finalFlexFieldValues.toArray());
            flexFields.setTypes(finalFlexFieldTypes.toArray(new String[0]));

            String folderIdString = artifactData.getFolderId();
            if (trackerId != null && trackerId.getFieldValueHasChanged()) {
                folderIdString = (String) trackerId.getFieldValue();
                artifactData.setFolderId(folderIdString);
            }

            if (title != null && title.getFieldValueHasChanged()) {
                artifactData.setTitle((String) title.getFieldValue());
            }

            if (description != null && description.getFieldValueHasChanged()) {
                artifactData.setDescription((String) description.getFieldValue());
            }

            if (group != null && group.getFieldValueHasChanged()) {
                artifactData.setGroup((String) group.getFieldValue());
            }

            if (category != null && category.getFieldValueHasChanged()) {
                artifactData.setCategory((String) category.getFieldValue());
            }

            if (status != null && status.getFieldValueHasChanged()) {
                artifactData.setStatus((String) status.getFieldValue());
            }

            if (customer != null && customer.getFieldValueHasChanged()) {
                artifactData.setCustomer((String) customer.getFieldValue());
            }

            if (priority != null && priority.getFieldValueHasChanged()) {
                Object fieldValueObj = priority.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 priority: " + e.getMessage(), e);
                    }
                } else if (fieldValueObj instanceof Integer) {
                    fieldValue = ((Integer) fieldValueObj).intValue();
                }
                artifactData.setPriority(fieldValue);
            }

            if (estimatedHours != null && estimatedHours.getFieldValueHasChanged()) {
                Object fieldValueObj = estimatedHours.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 estimatedHours: " + e.getMessage(),
                                e);
                    }
                } else if (fieldValueObj instanceof Integer) {
                    fieldValue = ((Integer) fieldValueObj).intValue();
                }
                artifactData.setEstimatedHours(fieldValue);
            }

            if (actualHours != null && actualHours.getFieldValueHasChanged()) {
                Object fieldValueObj = actualHours.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 actualHours: " + e.getMessage(), e);
                    }
                } else if (fieldValueObj instanceof Integer) {
                    fieldValue = ((Integer) fieldValueObj).intValue();
                }
                artifactData.setActualHours(fieldValue);
            }

            if (assignedTo != null && assignedTo.getFieldValueHasChanged()) {
                artifactData.setAssignedTo((String) assignedTo.getFieldValue());
            }

            if (statusClass != null && statusClass.getFieldValueHasChanged()) {
                artifactData.setStatusClass((String) statusClass.getFieldValue());
            }

            if (closeDate != null && closeDate.getFieldValueHasChanged()) {
                Object fieldValueObj = closeDate.getFieldValue();
                Date fieldValue = null;
                if (fieldValueObj instanceof String) {
                    String fieldValueString = (String) fieldValueObj;
                    fieldValue = DateUtil.parse(fieldValueString);
                } else if (fieldValueObj instanceof Date) {
                    fieldValue = (Date) fieldValueObj;
                }
                artifactData.setCloseDate(fieldValue);
            }

            if (reportedReleaseId != null && reportedReleaseId.getFieldValueHasChanged()) {
                String reportedReleaseIdString = (String) reportedReleaseId.getFieldValue();
                if (translateTechnicalReleaseIds) {
                    reportedReleaseIdString = convertReleaseId(sessionId, reportedReleaseIdString,
                            folderIdString);
                }
                artifactData.setReportedReleaseId(reportedReleaseIdString);
            }

            if (resolvedReleaseId != null && resolvedReleaseId.getFieldValueHasChanged()) {
                String resolvedReleaseIdString = (String) resolvedReleaseId.getFieldValue();
                if (translateTechnicalReleaseIds) {
                    resolvedReleaseIdString = convertReleaseId(sessionId, resolvedReleaseIdString,
                            folderIdString);
                }
                artifactData.setResolvedReleaseId(resolvedReleaseIdString);
            }

            artifactData.setFlexFields(flexFields);

            mTrackerApp.setArtifactData(sessionId, artifactData, null, null, null, null);
        } catch (AxisFault e) {
            javax.xml.namespace.QName faultCode = e.getFaultCode();
            if (!faultCode.getLocalPart().equals("VersionMismatchFault")) {
                throw e;
            }
            logConflictResolutor.warn("Stale update for TF tracker item " + Id + " in tracker " + trackerId
                    + ". Trying again ...", e);
            mainArtifactNotUpdated = true;
        }
    }
    // increase version number for comment updates
    if (comments.length != 0) {
        artifactData.setVersion(artifactData.getVersion() + 1);
    }

    for (String comment : comments) {
        boolean commentNotUpdated = true;
        while (commentNotUpdated) {
            try {
                commentNotUpdated = false;
                if (StringUtils.isEmpty(comment)) {
                    continue;
                }
                mTrackerApp.setArtifactData(sessionId, artifactData, comment, null, null, null);
                artifactData.setVersion(artifactData.getVersion() + 1);
            } catch (AxisFault e) {
                javax.xml.namespace.QName faultCode = e.getFaultCode();
                if (!faultCode.getLocalPart().equals("VersionMismatchFault")) {
                    throw e;
                }
                logConflictResolutor.warn("Stale comment update, trying again ...:", e);
                artifactData = mTrackerApp.getArtifactData(sessionId, Id);
                commentNotUpdated = true;
            }
        }
    }

    // since TF 5.3, we cannot be sure that the version number has increased automatically
    if (comments.length == 0) {
        // artifactData.setVersion(artifactData.getVersion() + 1);
        artifactData = mTrackerApp.getArtifactData(sessionId, Id);
    }
    log.info("Artifact updated id: " + artifactData.getId() + " in tracker " + artifactData.getFolderId());
    return artifactData;
}

From source file:com.centeractive.ws.builder.soap.XmlUtils.java

public static void setXsiType(Element elm, QName name) {
    String prefix = findPrefixForNamespace(elm, name.getNamespaceURI());
    if (prefix == null) {
        prefix = generatePrefixForNamespace(name.getNamespaceURI());
        while (findNamespaceForPrefix(elm, prefix) != null) {
            prefix = generatePrefixForNamespace(name.getNamespaceURI());
        }//ww w .  j  av  a2s. c  om

        elm.setAttribute("xmlns:" + prefix, name.getNamespaceURI());
    }

    elm.setAttributeNS(Constants.XSI_NS, "type", prefix + ":" + name.getLocalPart());
}

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

/**
 * Adds XSD element definition created from the PrismReferenceDefinition.
 * TODO: need to finish/*from  ww  w.j a  va  2s.c o  m*/
 */
private void addReferenceDefinition(PrismReferenceDefinition definition, Element parent) {
    Element property = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "element"));
    // Add to document first, so following methods will be able to resolve namespaces
    parent.appendChild(property);

    String attrNamespace = definition.getName().getNamespaceURI();
    if (attrNamespace != null && attrNamespace.equals(getNamespace())) {
        setAttribute(property, "name", definition.getName().getLocalPart());
        setQNameAttribute(property, "type", definition.getTypeName());
    } else {
        setQNameAttribute(property, "ref", definition.getName());
    }

    if (definition.getCompositeObjectElementName() == null) {
        setMultiplicityAttribute(property, "minOccurs", 0);
    }
    setMultiplicityAttribute(property, "maxOccurs", definition.getMaxOccurs());

    // Add annotations
    Element annotation = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "annotation"));
    property.appendChild(annotation);
    Element appinfo = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "appinfo"));
    annotation.appendChild(appinfo);

    addAnnotation(A_OBJECT_REFERENCE, appinfo);

    if (definition.getTargetTypeName() != null) {
        addAnnotation(A_OBJECT_REFERENCE_TARGET_TYPE, definition.getTargetTypeName(), appinfo);
    }

    if (definition.getCompositeObjectElementName() == null) {
        return;
    }

    property = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "element"));
    // Add to document first, so following methods will be able to resolve namespaces
    parent.appendChild(property);

    QName elementName = definition.getCompositeObjectElementName();
    attrNamespace = elementName.getNamespaceURI();
    if (attrNamespace != null && attrNamespace.equals(getNamespace())) {
        setAttribute(property, "name", elementName.getLocalPart());
        setQNameAttribute(property, "type", definition.getTargetTypeName());
    } else {
        setQNameAttribute(property, "ref", elementName);
    }

    setMultiplicityAttribute(property, "minOccurs", 0);
    setMultiplicityAttribute(property, "maxOccurs", definition.getMaxOccurs());

    // Add annotations
    annotation = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "annotation"));
    property.appendChild(annotation);
    appinfo = createElement(new QName(W3C_XML_SCHEMA_NS_URI, "appinfo"));
    annotation.appendChild(appinfo);

    addAnnotation(A_OBJECT_REFERENCE, definition.getName(), appinfo);
    if (definition.isComposite()) {
        addAnnotation(A_COMPOSITE, definition.isComposite(), appinfo);
    }

    SchemaDefinitionFactory definitionFactory = getDefinitionFactory();
    definitionFactory.addExtraReferenceAnnotations(definition, appinfo, this);

}