Création d'un type de propriété puis ajout de ce nouvel élément à un type d'entité existant

Vous pouvez utiliser les exemples de graphique de données et le fragment de code fournis ici pour créer un type de propriété, age, et l'ajouter à un type d'entité existant, PersonAccount.

Graphique de données d'entrée

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:schema>
      <wim:propertySchema nsPrefix="yourext" nsURI="http://www.yourco.com/wim/yourext"
          dataType="Int" multiValued="false" propertyName="age">
        <wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
      </wim:propertySchema>
    </wim:schema>
  </wim:Root>
</sdo:datagraph>

Graphique de données de sortie

Le graphique de données renvoyé contient les ID des référentiels qui prennent en charge ce nouveau type de propriété.
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:Root>
    <wim:schema>
      <wim:propertySchema nsPrefix="yourext" nsURI="http://www.yourco.com/wim/yourext"
          dataType="Int" multiValued="false" propertyName="age">
        <wim:repositoryIds>LDAP1</wim:repositoryIds>
        <wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
      </wim:propertySchema>
    </wim:schema>
  </wim:Root>
</sdo:datagraph>

Fichier wimxmlextension.xml

Une fois le schéma créé, le fichier wimxmlextension.xml ressemble au fragment de code suivant :
<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:sdo="commonj.sdo"
    xmlns:wim="http://www.ibm.com/websphere/wim">
  <wim:schema>
    <wim:propertySchema nsPrefix="yourext" nsURI="http://www.yourco.com/wim/yourext"
        dataType="Int" multiValued="false" propertyName="age">
      <wim:applicableEntityTypeNames>PersonAccount</wim:applicableEntityTypeNames>
    </wim:propertySchema>
  </wim:schema>
</sdo:datagraph>
Remarque : Pour plus d'informations sur l'utilisation des objets de données propertySchema et extensionPropertySchema, voir la section Schéma de propriété étendu de la rubrique Prérequis pour la programmation. Reportez-vous également à la rubrique Configuration d'un référentiel d'extension de propriété dans une configuration de référentiel fédéré dans le centre de documentation WebSphere Application Server.

Exemple de code

A l'aide du code suivant, vous pouvez créer le type de propriété age et l'ajouter à un type d'entité existant, PersonAccount.

private static String dynaextURI = "http://www.yourco.com/wim/yourext";
private static String dynaextPrefix = "yourext";
String newPropName = "age";

    try {

        System.out.println("\nCLIENT: Create new property type and add it to existing entity type PersonAccount...");
        DataObject root = service.createRootDataObject();
        DataObject dynaSchemaDO = root.createDataObject(SchemaConstants.DO_SCHEMA);

        // créer une propriété
        DataObject propSchemaDO = dynaSchemaDO.createDataObject(SchemaConstants.DO_EXTENSION_PROPERTY_SCHEMA);
        propSchemaDO.set(SchemaConstants.PROP_NS_URI, dynaextURI);
        propSchemaDO.set(SchemaConstants.PROP_NS_PREFIX, dynaextPrefix);

        propSchemaDO.set(SchemaConstants.PROP_PROPERTY_NAME, newPropName);
        propSchemaDO.setBoolean(SchemaConstants.PROP_MULTI_VALUED, false);
        propSchemaDO.set(SchemaConstants.PROP_DATA_TYPE, SchemaConstants.DATA_TYPE_INT);
        List applicableEntityTypes = propSchemaDO.getList(SchemaConstants.PROP_APPLICABLE_ENTITY_TYPE_NAMES);
        applicableEntityTypes.add("PersonAccount");

        SDOUtils.printDataGraph(INPUT_DATAGRAPH, root);
        service.createSchema(root);
        System.out.println("\nCLIENT: new property type is created.");
    }
    catch (Exception e) {
        printException(e);
    }


Conditions d'utilisation | Commentaires