Ejemplo n.º 1
0
  /**
   * INTERNAL: Convenience method that sets up class indicator and @sdoRef attribute.
   *
   * @param xdesc
   * @param pCls
   */
  private void addClassIndicator(XMLDescriptor xdesc, Class pCls, boolean isInheritanceRoot) {
    XMLField field = (XMLField) getXmlDescriptor().buildField("@xsi:type");
    xdesc.getInheritancePolicy().setClassIndicatorField(field);

    String parentIndicator = getName();
    String parentPrefix = xdesc.getNamespaceResolver().resolveNamespaceURI(getURI());
    if (parentPrefix != null) {
      parentIndicator =
          parentPrefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + parentIndicator;
    }
    xdesc.getInheritancePolicy().addClassIndicator(pCls, parentIndicator);

    // only add the @sdoRef attribute if necessary
    if (xdesc.getMappingForAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME) == null) {
      String sdoPrefix =
          ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(SDOConstants.SDO_URL);
      XMLDirectMapping sdoRefMapping = new XMLDirectMapping();
      sdoRefMapping.setAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME);

      XMLField xmlField =
          new XMLField(
              "@"
                  + sdoPrefix
                  + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT
                  + SDOConstants.CHANGESUMMARY_REF);
      xmlField.getXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
      xmlField.getLastXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);

      sdoRefMapping.setField(xmlField);
      xdesc.addMapping(sdoRefMapping);
    }
  }
  protected XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    // descriptor.setDefaultRootElement("employee");
    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setXPath("id/text()");
    idMapping.setAttributeName("id");
    descriptor.addMapping(idMapping);

    XMLCompositeObjectMapping emailMapping = new XMLCompositeObjectMapping();
    emailMapping.setAttributeName("emailAddress");
    emailMapping.setXPath("info/email-address");
    emailMapping.setGetMethodName("getEmailAddress");
    emailMapping.setSetMethodName("setEmailAddress");
    emailMapping.setReferenceClass(EmailAddress.class);
    descriptor.addMapping(emailMapping);

    URL schemaURL =
        ClassLoader.getSystemResource("org/eclipse/persistence/testing/oxm/jaxb/Employee.xsd");
    XMLSchemaURLReference schemaRef = new XMLSchemaURLReference(schemaURL);
    schemaRef.setType(XMLSchemaURLReference.COMPLEX_TYPE);
    schemaRef.setSchemaContext("employee-root");
    descriptor.setSchemaReference(schemaRef);

    /*
    NamespaceResolver try_test = new NamespaceResolver();
    try_test.put("xsi", XMLConstants.SCHEMA_INSTANCE_URL);
    descriptor.setNamespaceResolver(try_test);*/
    return descriptor;
  }
  protected ClassDescriptor buildInheritancePolicyDescriptor() {
    ClassDescriptor descriptor = super.buildInheritancePolicyDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("parentClass");
    referenceClassMapping.setGetMethodName("getParentClassName");
    referenceClassMapping.setSetMethodName("setParentClassName");

    return descriptor;
  }
  protected ClassDescriptor buildTransformerBasedFieldTransformationDescriptor() {
    ClassDescriptor descriptor = super.buildTransformerBasedFieldTransformationDescriptor();

    XMLDirectMapping objectClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("transformerClass");
    objectClassMapping.setGetMethodName("getTransformerClassName");
    objectClassMapping.setSetMethodName("setTransformerClassName");

    return descriptor;
  }
  protected ClassDescriptor buildAbstractDirectMappingDescriptor() {
    ClassDescriptor descriptor = super.buildAbstractDirectMappingDescriptor();

    XMLDirectMapping attributeClassificationNameMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("attributeClassification");
    attributeClassificationNameMapping.setGetMethodName("getAttributeClassificationName");
    attributeClassificationNameMapping.setSetMethodName("setAttributeClassificationName");

    return descriptor;
  }
  protected ClassDescriptor buildTypedAssociationDescriptor() {
    ClassDescriptor descriptor = super.buildTypedAssociationDescriptor();

    XMLDirectMapping keyMapping = (XMLDirectMapping) descriptor.getMappingForAttributeName("key");
    keyMapping.setAttributeClassification(null);
    keyMapping.setGetMethodName("getKey");
    keyMapping.setSetMethodName("setKey");

    return descriptor;
  }
  protected ClassDescriptor buildQueryArgumentDescriptor() {
    ClassDescriptor descriptor = super.buildQueryArgumentDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("type");
    referenceClassMapping.setGetMethodName("getTypeName");
    referenceClassMapping.setSetMethodName("setTypeName");

    return descriptor;
  }
  protected ClassDescriptor buildMethodBaseQueryRedirectorDescriptor() {
    ClassDescriptor descriptor = super.buildMethodBaseQueryRedirectorDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("methodClass");
    referenceClassMapping.setGetMethodName("getMethodClassName");
    referenceClassMapping.setSetMethodName("setMethodClassName");

    return descriptor;
  }
  protected ClassDescriptor buildInstantiationPolicyDescriptor() {
    ClassDescriptor descriptor = super.buildInstantiationPolicyDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("factoryClass");
    referenceClassMapping.setGetMethodName("getFactoryClassName");
    referenceClassMapping.setSetMethodName("setFactoryClassName");

    return descriptor;
  }
  protected ClassDescriptor buildInterfaceContainerPolicyDescriptor() {
    ClassDescriptor descriptor = super.buildInterfaceContainerPolicyDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("containerClass");
    referenceClassMapping.setGetMethodName("getContainerClassName");
    referenceClassMapping.setSetMethodName("setContainerClassName");

    return descriptor;
  }
  protected ClassDescriptor buildForeignReferenceMappingDescriptor() {
    ClassDescriptor descriptor = super.buildForeignReferenceMappingDescriptor();

    XMLDirectMapping referenceClassMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("referenceClass");
    referenceClassMapping.setGetMethodName("getReferenceClassName");
    referenceClassMapping.setSetMethodName("setReferenceClassName");

    return descriptor;
  }
Ejemplo n.º 12
0
  /** Set the value on the underlying POJO, unwrapping values as necessary. */
  public void setDeclaredProperty(int propertyIndex, Object value) {
    SDOProperty declaredProperty =
        (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    if (declaredProperty.getType().isChangeSummaryType()) {
      return;
    }

    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);

    Object newValue = value;
    Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);

    if (declaredProperty.getType().isDataType()) {
      if (!declaredProperty.isMany()) {
        AbstractSession session =
            ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
        XMLDirectMapping directMapping = (XMLDirectMapping) mapping;
        if (directMapping.hasConverter()) {
          newValue = directMapping.getConverter().convertDataValueToObjectValue(newValue, session);
        } else {
          CoreField field = mapping.getField();
          newValue =
              session
                  .getDatasourcePlatform()
                  .getConversionManager()
                  .convertObject(
                      newValue,
                      descriptor.getObjectBuilder().getFieldClassification((XMLField) field));
        }
      }
      mapping.setAttributeValueInObject(entity, newValue);
    } else if (declaredProperty.isMany()) {
      // Get a ListWrapper and set it's current elements
      ListWrapper listWrapper = (ListWrapper) getDeclaredProperty(propertyIndex);
      listWrapper.addAll((List) newValue);
    } else {
      // OLD VALUE
      if (mapping.isAbstractCompositeObjectMapping()) {
        XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
        if (oldValue != null && compositeMapping.getContainerAccessor() != null) {
          compositeMapping.getContainerAccessor().setAttributeValueInObject(oldValue, null);
        }
      }

      // NEW VALUE
      newValue = jaxbHelperContext.unwrap((DataObject) value);
      mapping.getAttributeAccessor().setAttributeValueInObject(entity, newValue);
      if (mapping.isAbstractCompositeObjectMapping()) {
        XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
        if (value != null && compositeMapping.getContainerAccessor() != null) {
          compositeMapping.getContainerAccessor().setAttributeValueInObject(newValue, entity);
        }
      }
    }
  }
Ejemplo n.º 13
0
  public void addEmployeeDescriptor(boolean methodAccess) {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");

    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    descriptor.addMapping(idMapping);

    XMLDirectMapping firstNameMapping = new XMLDirectMapping();
    firstNameMapping.setAttributeName("firstName");
    firstNameMapping.setXPath("first-name/text()");
    descriptor.addMapping(firstNameMapping);

    XMLDirectMapping lastNameMapping = new XMLDirectMapping();
    lastNameMapping.setAttributeName("lastName");
    lastNameMapping.setXPath("last-name/text()");
    descriptor.addMapping(lastNameMapping);

    XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
    addressMapping.setAttributeName("address");
    addressMapping.setReferenceClass(Address.class);
    addressMapping.setXPath("address");
    descriptor.addMapping(addressMapping);

    XMLCompositeCollectionMapping phoneMapping = new XMLCompositeCollectionMapping();
    phoneMapping.setAttributeName("phoneNumbers");
    phoneMapping.setReferenceClass(PhoneNumber.class);
    phoneMapping.setXPath("phone-numbers/number");
    phoneMapping.setContainerPolicy(ContainerPolicy.buildPolicyFor(ArrayList.class));
    descriptor.addMapping(phoneMapping);
    this.addDescriptor(descriptor);
  }
  public XMLDescriptor getAddressDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Address.class);

    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("street");
    idMapping.setXPath("@street");
    xmlDescriptor.addMapping(idMapping);

    return xmlDescriptor;
  }
Ejemplo n.º 15
0
  public void addPhoneNumberDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(PhoneNumber.class);

    XMLDirectMapping numberMapping = new XMLDirectMapping();
    numberMapping.setAttributeName("number");
    numberMapping.setXPath("text()");
    descriptor.addMapping(numberMapping);

    this.addDescriptor(descriptor);
  }
  public void addAddressDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Address.class);

    XMLDirectMapping street = new XMLDirectMapping();
    street.setAttributeName("street");
    street.setXPath("street/text()");
    descriptor.addMapping(street);

    this.addDescriptor(descriptor);
  }
  @Override
  protected ClassDescriptor buildPLSQLrecordDescriptor() {

    ClassDescriptor descriptor = super.buildPLSQLrecordDescriptor();
    XMLDirectMapping javaTypeMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("javaType");
    javaTypeMapping.setGetMethodName("getJavaTypeName");
    javaTypeMapping.setSetMethodName("setJavaTypeName");

    return descriptor;
  }
  @Override
  protected ClassDescriptor buildStoredProcedureArgumentDescriptor() {

    ClassDescriptor descriptor = super.buildStoredProcedureArgumentDescriptor();

    XMLDirectMapping argumentTypeMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("argumentType");
    argumentTypeMapping.setGetMethodName("getArgumentTypeName");
    argumentTypeMapping.setSetMethodName("setArgumentTypeName");

    return descriptor;
  }
 protected ClassDescriptor buildAddressDescriptor() {
   XMLDescriptor descriptor = new XMLDescriptor();
   descriptor.setJavaClass(Address.class);
   descriptor.setDefaultRootElement("address");
   XMLDirectMapping mapping = new XMLDirectMapping();
   mapping.setAttributeName("address_content");
   mapping.setGetMethodName("getContent");
   mapping.setSetMethodName("setContent");
   mapping.setXPath("text()");
   descriptor.addMapping(mapping);
   return descriptor;
 }
Ejemplo n.º 20
0
  public void addPhoneNumberDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(PhoneNumber.class);
    descriptor.setDefaultRootElement("phone-number");

    XMLDirectMapping num = new XMLDirectMapping();
    num.setAttributeName("number");
    num.setXPath("text()");
    descriptor.addMapping(num);

    this.addDescriptor(descriptor);
  }
Ejemplo n.º 21
0
  public XMLDescriptor addAddressDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Address.class);
    descriptor.setDefaultRootElement("address");

    XMLDirectMapping street = new XMLDirectMapping();
    street.setAttributeName("street");
    street.setXPath("street/text()");
    descriptor.addMapping(street);

    this.addDescriptor(descriptor);
    return descriptor;
  }
Ejemplo n.º 22
0
  private XMLDescriptor getAddressDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Address.class);

    NamespaceResolver nsResolver = new NamespaceResolver();
    nsResolver.put("ns", "urn:example");
    xmlDescriptor.setNamespaceResolver(nsResolver);

    XMLDirectMapping streetMapping = new XMLDirectMapping();
    streetMapping.setAttributeName("street");
    streetMapping.setXPath("text()");
    xmlDescriptor.addMapping(streetMapping);

    return xmlDescriptor;
  }
  public ClassDescriptor buildChildDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(AnyCollectionChild.class);
    descriptor.setDefaultRootElement("child");
    descriptor.addRootElement("someChild");

    XMLDirectMapping mapping = new XMLDirectMapping();
    mapping.setAttributeName("content");
    mapping.setGetMethodName("getContent");
    mapping.setSetMethodName("setContent");
    mapping.setXPath("text()");
    descriptor.addMapping(mapping);

    return descriptor;
  }
Ejemplo n.º 24
0
 public void setMixed(boolean isMixed) {
   String textAttribute = "text";
   XMLDirectMapping textMapping =
       (XMLDirectMapping) xmlDescriptor.getMappingForAttributeName(textAttribute);
   if (isMixed) {
     if (null == textMapping) {
       textMapping = new XMLDirectMapping();
       textMapping.setAttributeName(textAttribute);
       textMapping.setXPath("text()");
       xmlDescriptor.addMapping(textMapping);
     }
   } else {
     xmlDescriptor.removeMappingForAttributeName(textAttribute);
   }
 }
  protected ClassDescriptor buildInterfacePolicyDescriptor() {
    ClassDescriptor descriptor = super.buildInterfacePolicyDescriptor();

    XMLCompositeDirectCollectionMapping referenceClassMapping =
        (XMLCompositeDirectCollectionMapping)
            descriptor.getMappingForAttributeName("parentInterfaces");
    referenceClassMapping.setGetMethodName("getParentInterfaceNames");
    referenceClassMapping.setSetMethodName("setParentInterfaceNames");

    XMLDirectMapping implementorDescriptorMapping =
        (XMLDirectMapping) descriptor.getMappingForAttributeName("implementorDescriptor");
    implementorDescriptorMapping.setGetMethodName("getImplementorDescriptorClassName");
    implementorDescriptorMapping.setSetMethodName("setImplementorDescriptorClassName");

    return descriptor;
  }
  private void updateNullPolicyForAttribute(Project aProject, String attributeName) {

    AbstractNullPolicy aNullPolicy = new NullPolicy();
    // Alter unmarshal policy state
    ((NullPolicy) aNullPolicy).setSetPerformedForAbsentNode(true); // no effect
    aNullPolicy.setNullRepresentedByEmptyNode(true); // no effect
    aNullPolicy.setNullRepresentedByXsiNil(false); // no effect
    //  Alter marshal policy state
    aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
    XMLDirectMapping aMapping =
        (XMLDirectMapping)
            aProject
                .getDescriptor(Employee.class) //
                .getMappingForAttributeName(attributeName);
    aMapping.setNullPolicy(aNullPolicy);
  }
Ejemplo n.º 27
0
  /** INTERNAL: */
  public void postInitialize() {
    String idPropName = (String) get(SDOConstants.ID_PROPERTY);
    if (idPropName != null) {
      SDOProperty idProp = getProperty(idPropName);
      if (idProp != null) {
        String targetxpath = idProp.getQualifiedXPath(getURI(), true);
        getXmlDescriptor().addPrimaryKeyFieldName(targetxpath);
      }
    }
    setFinalized(true);
    if (null != nonFinalizedReferencingProps) {
      for (int i = 0; i < nonFinalizedReferencingProps.size(); i++) {
        SDOProperty nextProp = nonFinalizedReferencingProps.get(i);
        String nextURI = (String) getNonFinalizedMappingURIs().get(i);
        nextProp.buildMapping(nextURI, nextProp.getIndexInType());
      }
    }
    // set @sdoRef attribute mapping for complex types that are not involved in inheritance
    if (!isDataType() && !isSubType() && !isBaseType()) {
      String sdoPrefix =
          ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(SDOConstants.SDO_URL);
      XMLDirectMapping sdoRefMapping = new XMLDirectMapping();
      sdoRefMapping.setAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME);

      XMLField xmlField =
          new XMLField(
              "@"
                  + sdoPrefix
                  + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT
                  + SDOConstants.CHANGESUMMARY_REF);
      xmlField.getXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
      xmlField.getLastXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
      sdoRefMapping.setField(xmlField);
      xmlDescriptor.addMapping(sdoRefMapping);
    }
    if (!isDataType()) {
      getImplClass();
      if (!isAbstract() && !isWrapperType()) {
        TypeInstantiationPolicy tip = new TypeInstantiationPolicy(this);
        this.xmlDescriptor.setInstantiationPolicy(tip);
      }
    }
  }
  // Persistence
  public static XMLDescriptor buildDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(MWLiteralArgument.class);
    descriptor.getInheritancePolicy().setParentClass(MWArgument.class);

    // 1:1 - type
    XMLCompositeObjectMapping typeMapping = new XMLCompositeObjectMapping();
    typeMapping.setAttributeName("type");
    typeMapping.setReferenceClass(MWTypeDeclaration.class);
    typeMapping.setXPath("type");
    descriptor.addMapping(typeMapping);

    // DTF Object value
    XMLDirectMapping valueMapping =
        (XMLDirectMapping) descriptor.addDirectMapping("value", "value/text()");
    valueMapping.setNullValue("");

    return descriptor;
  }
  private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");

    XMLDirectMapping idMapping = new XMLDirectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("@id");
    descriptor.addMapping(idMapping);

    XMLCompositeCollectionMapping emailMapping = new XMLCompositeCollectionMapping();
    emailMapping.setAttributeName("emailAddresses");
    emailMapping.setReferenceClass(EmailAddress.class);
    emailMapping.setXPath("email-addresses/email-address");
    emailMapping.setReuseContainer(true);
    descriptor.addMapping(emailMapping);

    return descriptor;
  }
  public static XMLDescriptor legacy60BuildDescriptor() {
    XMLDescriptor descriptor = MWModel.legacy60BuildStandardDescriptor();

    descriptor.setJavaClass(MWTypeDeclaration.class);

    // 'type' will never be null
    XMLCompositeObjectMapping typeHandleMapping = new XMLCompositeObjectMapping();
    typeHandleMapping.setAttributeName("typeHandle");
    typeHandleMapping.setReferenceClass(MWClassHandle.class);
    typeHandleMapping.setGetMethodName("getTypeHandleForTopLink");
    typeHandleMapping.setSetMethodName("setTypeHandleForTopLink");
    typeHandleMapping.setXPath("type-handle");
    descriptor.addMapping(typeHandleMapping);

    XMLDirectMapping dimMapping =
        (XMLDirectMapping) descriptor.addDirectMapping("dimensionality", "dimensionality/text()");
    dimMapping.setNullValue(new Integer(0));

    return descriptor;
  }