ATG Repository User-Defined Property Types

ATG allows one to use your own Java class data types for the properties of repository items. This is called User-Defined Property Types.

While working with these user-defined property types I learned a few things that are not explicitly documented.

  1. The source for atg.repository.FilePropertyDescriptor is supplied in the installation and it’s a good example for creating your own user-defined property type.
  2. To set values of properties in your Java class data type do two things.
    1. Configure the values of these properties using the attribute tag. For example:

      <property name="contentFile" property-type="atg.repository.FilePropertyDescriptor">
      <attribute name="pathNameProperty" value="contentFileName"/>
      </property>
    2. Access these attributes and set the corresponding properties in the setValue() method. Continuing with the above example:

      public void setValue(String pAttributeName, Object pValue) {
      super.setValue(pAttributeName, pValue);

      if (pValue == null || pAttributeName == null) return;
      if (pAttributeName.equalsIgnoreCase(PATH_NAME_PROPERTY))
      mPathNameProperty = pValue.toString();
      if (pAttributeName.equalsIgnoreCase(PATH_PREFIX))
      mPathPrefix = pValue.toString();
      }
  3. ATG’s documentation suggests it is not necessary to define the data-type attribute if you specify the type with the property-type attribute. However I found that sometimes ATG gets confused and that it is best practice to always set the data-type. So using the above example one would do this.

    <property name="contentFile" data-type="string" property-type="atg.repository.FilePropertyDescriptor">
    <attribute name="pathNameProperty" value="contentFileName"/>
    </property>
  4. Only one instance of your user-defined property type is ever instantiated. Even if your user-defined property type is used for multiple properties it will still only be instantiated once.
  5. The JavaDoc for ATG’s RepositoryPropertyDescriptor class, which one typically extends to create ones own user-defined property type, documents the getPropertyValue method like this: public java.lang.Object getPropertyValue(RepositoryItemImpl pItem, java.lang.Object pValue)

    The first argument is the instance of the repository item whose property you are defining.

    The second argument would be better named pCachedPropertyValue because it is the cached property value. If it is null then that means there is no cached value. If it is not null that means that in a previous call setPropertyValueInCache(this, yourvalue) was called. Unfortunately this cached value is not that useful because since only one instance of your user-defined property type is ever created, the cached value will be a global value.

    This cached value is cleared when invalidateCaches is called on the repository item.

    Here is what ATG support said about caching with User-Defined Property Types.

    I think user defined properties will not be cached so that will cause your code to be
    called several times. If you require some caching you would properly have to
    implement it in the code of the user-defined property.

    As a user defined property could return data from any external source that might get
    updated independently of the ATG application we can not really make a decision on
    what should be cached and what should be retrieved anew every single time.

    Kind regards,
    Olaf Doemer

  6. The property descriptor implements the Serializable interface so the developer must ensure that it is indeed serializable, i.e. all its members are serializable.

10 thoughts on “ATG Repository User-Defined Property Types

  1. Do you know if it is possible to have a user defined property wherein an array of type RepositoryItems from another repository is being returned? I have the user-defined class that gets all related items as I can print them out to the console. But in ACC I get an error.
    Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
    at java.lang.Class.isAssignableFrom(Native Method)

  2. Honestly I don’t know but I would imagine it should be possible. If it is working within your code but not in the ACC then it’s an ACC specific issue. You might want to ask ATG support, support@atg.com.

  3. Thanks for getting back. Actually I got it to work. I had to set ‘isAssignableFrom()’to return ‘true’ as well as the ‘getPropertyType()’ to return ‘RepositoryItem[].class’ in my user-defined property class. Hope this info comes handy for you someday 🙂

  4. I apologize for taking as long as I did to reply. Maybe you could post how you did it here in the comments section. Or even better yet write a guest post on this blog on how you did it. Sounds quite cool. 🙂

  5. I have a user-defined property that gets me a set of sku information. Based on a dynamic value I want to return the sku info from my user-defined property class. How can I pass this dynamic value to the getProperty method ?

  6. Hi Karthik,
    That sounds like a tough problem. Where is this dynamic value? Can it be part of a session or even request scoped Nucleus component? If that’s the case you can access it using Nucleus.java’s method within your getProperty method.

  7. Thanks a lot Frank for your prompt response. That’s exactly what am doing now – Nucleus.getGlobalNucleus() and then referencing the value, but I am not comfortable with creating a new component specific for this or including this as part of a Nucleus component. And I am looking at a way where we can pass additional parameters to the getProperty method. ( I understand that on invoking getProperty method first invokes the super and then control comes to our custom property descriptor. It takes a RepositoryItem and Object as parameter, it would be great to know if we can tweak this out 🙂 )

  8. Karthik it sounds like you’re already ahead of where I was thinking. 🙂

    The getPropertyValue takes the instance of the repository item whose property you are defining as its first argument and the cached value as its second argument. I am not sure how you can tweak that but I remember hoping I could before too.

    Good luck and let me know if you do come up with a better solution.

  9. Hi Karthik,

    Did you get solution for your problem, actually I am stuck in same kind of problem and I don’t have request for resolving any session scoped component in getProperty method.

Leave a Reply

Your email address will not be published. Required fields are marked *