cancel
Showing results for 
Search instead for 
Did you mean: 

Webservice simpletypes restrictions

Former Member
0 Kudos

Hi all,

I'm trying to extract the constraints that are delivered with the wsdl of the webservice I've implemented. I'm using a separate node for mapping to my forms, so I need to extract the constraints from the webservice and assign it to the custom node (which are build from structures includes simpletypes with labels etc.).

In the wsdl I have entries like:


<xsd:simpleType name="char40">
    <xsd:restriction base="xsd:string">
        <xsd:maxLength value="40"/>
    </xsd:restriction>
</xsd:simpleType>

and 
<xsd:complexType name="ZcvClientRec">
    <xsd:sequence>
        .... 
        <xsd:element name="Birthname" type="n0:char40"/>
        .... 
    </xsd:sequence>
</xsd:complexType>

<xsd:element name="ZcvClientCreate">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="ClientData" type="tns:ZcvClientRec"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

I have created a custom controller through the service controller template, which all works well. For trying to extract the constraints, I've setup a temporary method in the custom controller, where I iterate through the model node attributes and print various simpletype attributes.


    IWDMessageManager manager = wdThis.wdGetAPI().getComponent().getMessageManager();
    Iterator attributeIterator = wdContext.nodeClientData().getNodeInfo().iterateAttributes();
    while (attributeIterator.hasNext()) {
        IWDAttributeInfo attribute = (IWDAttributeInfo)attributeIterator.next();
        ISimpleType simpleType = attribute.getSimpleType();
        manager.reportWarning("attribute info");
        manager.reportWarning("===================");

        manager.reportWarning("Name: " + attribute.getName());
        manager.reportWarning("isDeclared: " + (attribute.isDeclared() == true ? "true" : "false") );
        manager.reportWarning("isReadonly: " + (attribute.isReadOnly() == true ? "true" : "false") );
        manager.reportWarning("hasSimpleType: " + (attribute.hasSimpleType() == true ? "true" : "false") );
    
    
        manager.reportWarning("Type info");
        manager.reportWarning("===============");
    
        manager.reportWarning("Backend name: " + simpleType.getBackendName());
        manager.reportWarning("Build in type: " + simpleType.getBuiltInType());
        manager.reportWarning("Format: " + simpleType.getFormat());
        manager.reportWarning("Length: " + simpleType.getLength());
        manager.reportWarning("Name: " + simpleType.getName());
        manager.reportWarning("Pattern: " + simpleType.getPattern());
        manager.reportWarning("Max length: " + simpleType.getMaxLength());
        manager.reportWarning("Min length: " + simpleType.getMinLength());
    }

The result for "Birthname":

attribute info

===================

Name: Birthname

isDeclared: true

isReadonly: false

hasSimpleType: true

Type info

===============

Backend name: null

Build in type: string

Format: null

Length: 0

Name: com.sap.dictionary.string

Pattern: null

Max length: 0

Min length: 0

I would have expected the maxLength value to be filled with value 40, but that isn't the case.

So what am I missing here? Am I using the wrong approach? Do I need to access the CMI classes directly? Is this simply not possible?

To summarize:

I want to use the wsdl provided attribute constraints into my simpletyped and structured node attributes (without direct mappings).

I hope someone can help me with this. Thanks in advance!

Chris

ps. I'm using nw04 - sp19

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Ok, I got quite a lot further.


    ZcvClientRec record = new ZcvClientRec(model);
    
    Iterator assocModelIterator = record.associatedModelClassInfo().iteratePropertyInfos();
    
    while (assocModelIterator.hasNext()) {
        ICMIModelClassPropertyInfo propertyInfo = (ICMIModelClassPropertyInfo)assocModelIterator.next();
        manager.reportWarning("Name: " + propertyInfo.getName());
        manager.reportWarning("is Simpletype?: "+ propertyInfo.getDataType().isSimpleType());
        
        if (propertyInfo.getDataType().isSimpleType() == true) {
            
            ISimpleType wsSimpleType = (ISimpleType)propertyInfo.getDataType();
            manager.reportWarning("name: " + wsSimpleType.getName());
            manager.reportWarning("max length: " + wsSimpleType.getMaxLength());
            manager.reportWarning("built in type: " + wsSimpleType.getBuiltInType());
            manager.reportWarning("min length: " + wsSimpleType.getMinLength());
            manager.reportWarning("pattern: " + wsSimpleType.getPattern());
            manager.reportWarning("format: " + wsSimpleType.getFormat());

        }
    }

So I need to iterate through the modelclass properties, then get the data type and cast it to a simple type. In there I got the value of 40 with method getMaxLength. Yay!!! \o/

With this I can go ahead and 'dynamically' set the max length constraints from the wsdl into my simpletypes.

For the following situation:


<xsd:simpleType name="numeric8">
    <xsd:restriction base="xsd:string">
        <xsd:maxLength value="8"/>
        <xsd:pattern value="\d*"/>
    </xsd:restriction>
</xsd:simpleType>

i also need the pattern, but alas... getPattern or getFormat gives me a null pointer on this field.

Any thoughts?