[PDK] Creating a Dynamic Model for your Plug-in

Usually when you are creating a plug-in it is possible that you want to make changes on your model. For example, if you are working on a Input Adapter like the one we are creating here for RabbitMQ it is common that you want to support send data as String or as a ByteArray, and you want if you are going to send a String the input text to set the data should be coded as a String and if you want to send binary date (ByteArray) you want that the input text will be set like a binary field. This behavior it is common of the default activities at BusinessWorks. One example of that behavior it is on the Parse XML activity:

TIBCOBusinessStudio_2016-02-07_14-31-08TIBCOBusinessStudio_2016-02-07_14-32-54

TIBCOBusinessStudio_2016-02-07_14-31-24TIBCOBusinessStudio_2016-02-07_14-31-49

Ok, We understand now the behavior, but how can we do something like this? Ok, let’s go!

The most important thing is to understand all the project that you have inside your plugin. Today we are going to focus on the design project. This project have not only the current schema of the activites but have the java code to manage them. But first, I want talk about the approach we are going to follow here:

  • We need to create a parameter to manage the input type we are using. We are going to call it “Input Style” as you can see in the Parse Activity. We are used to do that, so no problem here.
  • Now, we need to return a different InputType depending on this behavior. But here we have a problem and I’m going to explain why:
    • We are going to focus on the design project as I said earlier because it has the classes to manage the input and output parameter of the activity.
    • The code that handles and gets the value of the configuration items it is on the runtime project.
    • We don’t have any attribute that links both of the clases.
  • Ok, to do that we have to focus on the “Signature” classes. If you analyze your code you are going to find a class that ends with “Signature” for each activity that you have. This class manages the activity signature (input, output and fault type declaration), as you can see here:

TIBCOBusinessStudio_2016-02-07_14-53-55

  • The main idea here is to modify this class, to do the logic that we need to modify the type declaration. But, as I said before, how can we get the value from the activity in this class? Ok, with the Configuration parameter that every method on this class has. But you have to be aware because you are going to work with downcasts to make it work! The logic should be something like this:

 

@Override
    public XSDElementDeclaration getInputType(final Configuration config) {
        XSDElementDeclaration inputType = null;
        inputType =  RabbitMQSenderSchema.getInputType();
        // begin-custom-code
        EList<ConfigProperty> props = config.getProperties();
        if (props != null && props.size() > 0) {
            com.tibco.bw.model.activityconfig.impl.EMFPropertyImpl p1 = (com.tibco.bw.model.activityconfig.impl.EMFPropertyImpl) props
                    .get(0);
            RabbitMQSenderImpl rabbitMqSender = (RabbitMQSenderImpl) p1.getValue();
            if (rabbitMqSender != null) {
                XSDElementDeclaration message = getChildElement(inputType, “message”,
                        false);
                if (message != null) {
                    if (!”String”.equals(rabbitMqSender.getInputStyle())) {
                        message.setTypeDefinition(XSDUtility
                                .getSimpleTypeDefinition(“base64Binary”));
                    } else {
                        message.setTypeDefinition(XSDUtility
                                .getSimpleTypeDefinition(“string”));
                    }
                }
            }

        }
        // end-custom-code
        return inputType;
    }

Ok, but we need to do another change. In our default schema we have defined message like a xsd: string but that’s not true, so we need to change it to anyType so we can store it both string value and binary value. To do that we use the wizard we already know and we change the type from string to anyType and we generate again the source code.

Be careful here, because when you generate the code you can lose some of the changes (the ones that are not between comments (add your custom code) but usually some imports and things should be gone. So, I recommend you to use a VCS each time you are working on this.

After done that, you have finish your work with the palette, but it is normal that you have to change something on your runtime project to handle these new formats of data. But when you launch your new plug-in, you are going to see something like this:

javaw_2016-02-07_15-53-06

javaw_2016-02-07_15-53-32javaw_2016-02-07_15-53-13

I hope you can use this new things in your next plug-in!!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s