Class AttributeDescriptor

    • Field Detail

      • DEFAULTVALUE

        public static final java.lang.String DEFAULTVALUE
        The default value attribute constant.
      • DEFAULTVALUE_DEFINITIONSTRING

        public static final java.lang.String DEFAULTVALUE_DEFINITIONSTRING
        The default value definiton string attribute constant.
      • DESCRIPTION

        public static final java.lang.String DESCRIPTION
        The description string attribute constant.
      • ENCLOSING_TYPE

        public static final java.lang.String ENCLOSING_TYPE
        The enclosing type string attribute constant.
      • DECLARING_ENCLOSING_TYPE

        public static final java.lang.String DECLARING_ENCLOSING_TYPE
        The declaring enclosing type string attribute constant.
      • WRITABLE

        public static final java.lang.String WRITABLE
        The writable string attribute constant.
      • READABLE

        public static final java.lang.String READABLE
        The readable string attribute constant.
      • REMOVABLE

        public static final java.lang.String REMOVABLE
        The removable string attribute constant.
      • OPTIONAL

        public static final java.lang.String OPTIONAL
        The optional string attribute constant.
      • SEARCH

        public static final java.lang.String SEARCH
        The search string attribute constant.
      • PARTOF

        public static final java.lang.String PARTOF
        The part of string attribute constant.
      • PRIVATE

        public static final java.lang.String PRIVATE
        The private string attribute constant.
      • PROPERTY

        public static final java.lang.String PROPERTY
        The property string attribute constant.
      • LOCALIZED

        public static final java.lang.String LOCALIZED
        The localized string attribute constant.
      • INHERITED

        public static final java.lang.String INHERITED
        The inherited string attribute constant.
      • UNIQUE

        public static final java.lang.String UNIQUE
        The unique string attribute constant.
      • INITIAL

        public static final java.lang.String INITIAL
        The initial string attribute constant.
      • TIM_IGNORE

        public static final java.lang.String TIM_IGNORE
        The do not optimize string attribute constant.
      • MODIFIERS

        public static final java.lang.String MODIFIERS
        The modifiers string attribute constant.
      • DATABASECOLUMN

        public static final java.lang.String DATABASECOLUMN
        The database column name string attribute constant.
      • PERSISTENCETYPE

        public static final java.lang.String PERSISTENCETYPE
        The persistence type string attribute constant.
      • ATTRIBUTE_HANDLER

        public static final java.lang.String ATTRIBUTE_HANDLER
        The attributeHandler string attribute constant.
      • PROPOSED_DATABASE_COLUMN

        public static final java.lang.String PROPOSED_DATABASE_COLUMN
        The proposed database column name string attribute constant.
      • PERSISTENCE_CLASS

        public static final java.lang.String PERSISTENCE_CLASS
        The persistence class string attribute constant.
      • ENCRYPTED

        public static final java.lang.String ENCRYPTED
        The encrypted string attribute constant.
      • PRIMITIVE

        public static final java.lang.String PRIMITIVE
        The primitive string attribute constant.
      • READ

        @Deprecated
        public static final java.lang.String READ
        Deprecated.
        since ages - please useREADABLEinstead
      • WRITE

        @Deprecated
        public static final java.lang.String WRITE
        Deprecated.
        since ages - please useWRITABLEinstead
      • REMOVE

        @Deprecated
        public static final java.lang.String REMOVE
        Deprecated.
        since ages - please useREMOVABLEinstead
      • ALL

        public static final int ALL
        All flags combined. Use for bit wise operations.
        See Also:
        Constant Field Values
      • ALL_PUBLIC

        public static final int ALL_PUBLIC
        All publicly changeable flags combined. Use for bit wise operations.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AttributeDescriptor

        public AttributeDescriptor()
    • Method Detail

      • setPropertyNonRecursively

        protected java.lang.Object setPropertyNonRecursively​(SessionContext ctx,
                                                             java.lang.String name,
                                                             java.lang.Object value)
        Sets a property without copying it down to all sub attribute descriptors.
        Parameters:
        ctx - the session context
        name - the property name
        value - the new value
        Returns:
        the old value
        Since:
        2.10 (previous method name contained a typo)
        See Also:
        setProperty(SessionContext, String, Object)
      • setLocalizedPropertyNonRecursively

        protected java.lang.Object setLocalizedPropertyNonRecursively​(SessionContext ctx,
                                                                      java.lang.String name,
                                                                      java.lang.Object value)
        Sets a localized property without copying it down to all sub attribute descriptors.
        Parameters:
        ctx - the session context defining the language
        name - the property name
        value - the new value
        Returns:
        the old value
        Since:
        2.10 (previous method name contained a typo)
        See Also:
        setLocalizedProperty(SessionContext, String, Object)
      • removeLocalizedProperty

        public java.lang.Object removeLocalizedProperty​(SessionContext ctx,
                                                        java.lang.String name)
        Removes a localized property. The property is also removed from all subattributes.
        Overrides:
        removeLocalizedProperty in class LocalizableItem
        Parameters:
        ctx - the session context defining the language
        name - the property name
        Returns:
        the localized property value which was removed
      • removeLocalizedPropertyNonRecursively

        protected java.lang.Object removeLocalizedPropertyNonRecursively​(SessionContext ctx,
                                                                         java.lang.String name)
        Removes a localized property without removing it from sub attributes too.
        Parameters:
        ctx - the session context defining the language
        name - the property name
        Since:
        2.10 (previous method name contained a typo)
      • removeProperty

        public java.lang.Object removeProperty​(SessionContext ctx,
                                               java.lang.String name)
        Removes a property. The property is also removed from all subattributes.
        Overrides:
        removeProperty in class ExtensibleItem
        Parameters:
        ctx - the session context
        name - the property name
        Returns:
        the property that was bound to the name before removal or null if there was no property.
      • removePropertyNonRecursively

        protected java.lang.Object removePropertyNonRecursively​(SessionContext ctx,
                                                                java.lang.String name)
        Removes a property without removing it from sub attributes too.
        Parameters:
        ctx - the session context
        name - the property name
        Since:
        2.10 (previous method name contained a typo)
      • getSubAttributeDescriptors

        public java.util.Set<AttributeDescriptor> getSubAttributeDescriptors()
        Returns direct sub attribute descriptors of this attribute. These are the attribute descriptors copied for direct subtypes of this attribute descriptor's enclosing type.
      • getAllSubAttributeDescriptors

        public java.util.Set<AttributeDescriptor> getAllSubAttributeDescriptors()
        Returns all sub attribute descriptors of this attribute. These are the attribute descriptors copied for all subtypes of this attribute descriptor's enclosing type.
      • getName

        public java.lang.String getName​(SessionContext ctx)
        Returns the name of this attribute descriptor. In case no name was set and the attribute descriptor has been inherited it tries to fetch the name from its super attribute descriptior(s).
        Overrides:
        getName in class TypeManagerManaged
        Parameters:
        ctx - the session context defining the language to get the name for
        Returns:
        the name of this type system item localized for the specified session context
      • getAllNames

        public java.util.Map getAllNames()
        Returns all names of this attribute descriptor as map. In case some names were not set and the attribute descriptor has been inherited it tries to fill the names map from its super attribute descriptior(s).
        Overrides:
        getAllNames in class TypeManagerManaged
      • setAttributeType

        public void setAttributeType​(Type type)
                              throws JaloInvalidParameterException
        Changes the value type of this attribute descriptor.

        This functionality should be used rarely since attribute type changes may impose different handling of item instances by all applications using this type. Generally attribute type changes should be done during system initialization or similar steps.

        Parameters:
        type - the new value type
        Throws:
        JaloInvalidParameterException - in case the previous type was not assignable from the new one; if the attribute has been inherited the previous type is taken from the super attribute
      • getDeclaringEnclosingType

        public ComposedType getDeclaringEnclosingType()
        If the attribute has been inherited this returns the type which originally declared this attribute. Otherwise it just returns the own enclosing type.
      • getEnclosingType

        public ComposedType getEnclosingType()
        The composed type which owns this attribute descriptor.
      • setModifiers

        public void setModifiers​(int modifiers)
      • isReadable

        public boolean isReadable()
        Returns:
        true if the attribute is readable.
        See Also:
        setReadable(boolean)
      • setReadable

        public void setReadable​(boolean readable)
                         throws JaloInvalidParameterException
        Changes the attribute describtor's readable status.

        Please note that changing an attribute descritors readability cannot affect the actual implementation ( see AttributeAccess). If an implementation does not allow reading the value setting the attribute descriptor readable doesnt make much sense.

        Throws:
        JaloInvalidParameterException
        See Also:
        isReadable()
      • isWriteable

        @Deprecated
        public boolean isWriteable()
        Deprecated.
        since ages - useisWritable()
        Returns:
        true if the attribute is writable.
        See Also:
        setWritable(boolean)
      • isWritable

        public boolean isWritable()
        Returns true if the attribute is writable.
        See Also:
        setWritable(boolean)
      • setWritable

        public void setWritable​(boolean writable)
                         throws JaloInvalidParameterException
        Changes the attribute describtor's writable status.

        Please note that changing an attribute descritors writability cannot affect the actual implementation ( see AttributeAccess). If an implementation does not allow writing the value setting the attribute descriptor writable doesnt make much sense.

        Throws:
        JaloInvalidParameterException
        See Also:
        isWritable()
      • isRemovable

        public boolean isRemovable()
        Tells whether or not this attribute is is allowed to be removed. Only removable attribute descriptors are allowed to be removed via Item.remove().

        The remove flag is intented to provide a certain safety for the type system designer to mark all required attribute as non-removable contrary to attribute descriptors created during system runtime which may be removed again.

        See Also:
        setRemovable(boolean)
      • setRemovable

        public void setRemovable​(boolean removable)
                          throws JaloInvalidParameterException
        Changes whether or not this attribute is is allowed to be removed. Only removable attribute descriptors are allowed to be removed via Item.remove().

        The remove flag is intented to provide a certain safety for the type system designer to mark all required attribute as non-removable contrary to attribute descriptors created during system runtime which may be removed again.

        Throws:
        JaloInvalidParameterException
        See Also:
        isRemovable()
      • isSearchable

        public boolean isSearchable()
        Tells whether a attribute is searchable or not. Usually this may only be true if the attribute has got persistence informations like getDatabaseColumn()and getPersistenceClass().
      • setSearchable

        public void setSearchable​(boolean searchable)
                           throws JaloInvalidParameterException
        Changes the searchable flag of this attribute descriptor.

        Please note that setting an attribute descriptor searchable which does not have persistence informations doesnt make much sense ( unless the FlexibleSearch was replaced by a search engine which is capable of searching such fields ).

        Throws:
        JaloInvalidParameterException - in case the persistence information does not allow this attribute to be made searchable
      • isPartOf

        public boolean isPartOf()
        Tells whether this attribute descriptor describes a part-of relation or not.

        Part-of attributes describe fields which store references to items which belong to the owner of the attribute.

        To name one example: AbstractOrder.entries where the AbstractOrder instance owns a collection of AbstractOrderEntry instances. Since one entry belongs to this order exclusively the entries attribute is marked as being part of .

        See Also:
        setPartOf(boolean)
      • getDontOptimize

        public boolean getDontOptimize()
        Tells whether this attribute descriptor has an "optimized" database layout or is stored in the dump table (dontOptimize=true).
        See Also:
        setDontOptimize(boolean)
      • isEncrypted

        public boolean isEncrypted()
        Tells whether this attribute should be stored in an encrypted way
        See Also:
        setEncrypted(boolean)
      • isPrimitive

        public boolean isPrimitive()
        Tells whether this attribute represents a java primitive type.
      • setPrivate

        public void setPrivate​(boolean priv)
        Changes the private flag of this attribute descriptor.
        Parameters:
        priv - the new private status
        See Also:
        isPrivate()
      • setDontOptimize

        public void setDontOptimize​(boolean dontopt)
        Changes the optimize flag of this attribute descriptor.
        Parameters:
        dontopt - the new dont optimize status
        See Also:
        getDontOptimize()
      • setEncrypted

        public void setEncrypted​(boolean encrypt)
        Changes the encrypted flag of this attribute descriptor.
        Parameters:
        encrypt - the new encrypt status
        See Also:
        isEncrypted()
      • setPrimitive

        public void setPrimitive​(boolean primitive)
        Changes the primitive flag of this attribute descriptor.
        Parameters:
        primitive - the new primitive status
      • isLocalized

        public boolean isLocalized()
        Tells whether an attribute is localized or not. Localized attributes hold multiple values, one per language. Therefore the attribute descriptor's value type must be a MapTypehaving the language item type as argument type and the actual attribute value type as return type.

        An example:

        
                TypeManager tm = jaloSession.getTypeManager();
                // we like to define a new localized attribute holding users
                ComposedType userType = tm.getComposedType( User.class );
                ComposedType langType = tm.getComposedType( Language.class );
        
                ComposedType myType = ...
                myType.createAttributeDescriptor(
                        "myAttribute",
                        tm.createMapType("locUserType", langType, userType),
                        AttributeDescriptor.READ_FLAG + AttributeDescriptor.WRITE_FLAG +
                                AttributeDescriptor.OPTIONAL_FLAG + AttributeDescriptor.PROPERTY_FLAG
                );
        
         

        Another diference between unlocalized and localized attributes is the result of Item.getAttribute(SessionContext, String). As long as the specified session context contains a session language the result will be the value mapped to this language. If no language is specified the result will contain all values in form of a map containing language-to-value mappings!
        The same rule applies to Item.setAttribute(SessionContext, String, Object).

        See Also:
        setLocalized(boolean)
      • setLocalized

        public void setLocalized​(boolean localized)
                          throws JaloInvalidParameterException
        Changes localized flag of this attribute descriptor. Only attributes holding a MapTypewith a language composed type as their argumenttype as attribute value type may become localized.

        Generally changing an attribute's localization status should seldom be necessary since during attribute creation the persistence settings have been chosen anyway which defines clearly if the field is localized or not.

        Parameters:
        localized - the new localized status
        Throws:
        JaloInvalidParameterException - in case the attribute value type doesnt allow attribute to be localized.
      • isInherited

        public boolean isInherited()
        Tells whether an attribute descriptor was inherited or not. Inherited attribute descriptors are copies of the same attribute descriptor belonging to the direct supertype of its enclosing type.
      • isInitial

        public boolean isInitial()
        Tells whether an attribute is initial or not.

        More precisely this flag would be named initially writable which means the attribute value may be written during instance creation. Usually it is used in combination with setting the writable flag to false which describes a field which has to be filled during creation but cannot be changed afterwards.

      • setInitial

        public void setInitial​(boolean initial)
        Changes the initial flag of this attribute descriptor.
        Parameters:
        initial - the new initial flag
      • setProperty

        public void setProperty​(boolean isProperty)
                         throws JaloInvalidParameterException
        Changes the property flag of this attribute descriptor.

        If true the attribute is backed by a property field. Each property attribute owns automatically a AttributeAccess which redirects to property getter and setter methods. Nevertheless it is possible to register a own access for this attribute as well.

        Please note that setting this flag to false requires that a own AttributeAccessis registered. Otherwise each access to this attribute will raise an exception from now on.

        Parameters:
        isProperty - the new property flag status
        Throws:
        JaloInvalidParameterException - in case the enclosing type does not describe a subclass of ExtensibleItem
        See Also:
        isProperty()
      • isUnique

        public boolean isUnique()
        Tells whether this attribute is unique.

        Unique attributes describe the fact that no two instances (of the enclosing type) may hold the same value within this attribute.

        Please note that right now there is no automatic check built in hybris platform - each AttributeAccess will need to implement its own check. This may change in future releases.

      • setUnique

        public void setUnique​(boolean unique)
        Changes the unique flag of this attribute descriptor.
        Parameters:
        unique - the new unique status.
      • setAttributeHandler

        public void setAttributeHandler​(java.lang.String attributeHandler)
      • getAttributeHandler

        public java.lang.String getAttributeHandler()
      • getDefaultValueDefinitionString

        public java.lang.String getDefaultValueDefinitionString()
        Returns the defaul value definition from items.xml in case this attribute was declared there having a <defaultvalue> tag. Otherwise null is returned.
        See Also:
        getXMLDefinition()
      • getDefaultValue

        public java.lang.Object getDefaultValue()
        Returns the default value of this attribute descriptor or null if no value was set and there is no default value defined for the attribute value type. If the value provides a default value this one is taken if the attribute doesnt provide a own value.

        Please note that the default value for the current session context is retrieved: for localized attributes the value belonging to the current session language!

        See Also:
        setDefaultValue(Object), setDefaultValue(SessionContext, Object)
      • getDefaultValue

        public java.lang.Object getDefaultValue​(SessionContext ctx)
        Returns the default value of this attribute descriptor or null if no value was set and there is no default value defined for the attribute value type. If the value provides a default value this one is taken if the attribute doesnt provide a own value.

        Please note that the default value for the specified session context is retrieved: for localized attributes the value belonging to the current session language! If no language is set or the context is null all localized values are returned in form of a map holding language-to-value mappings.

        Parameters:
        ctx - the session context specifying the language ( affect for localized attributes only )
        See Also:
        setDefaultValue(Object), setDefaultValue(SessionContext, Object)
      • interpretAndReplaceDefaultValue

        protected java.lang.Object interpretAndReplaceDefaultValue​(java.lang.Object current)
      • setDefaultValue

        public void setDefaultValue​(SessionContext ctx,
                                    java.lang.Object value)
                             throws JaloInvalidParameterException
        Changes the default value of this attribute.

        Please note that the value is set using the specified session context. For localized attributes this means the value belonging to the current session language is changed - all other stay unchanged. If no language is set the value must be a map containing all localized values as language-to-value mappings.
        Unlocalized attributes are not affected by session context.

        Parameters:
        ctx - the session context specifying the language
        value - the new default value
        Throws:
        JaloInvalidParameterException - in case the new value is not compatible with the attribute value type.
        See Also:
        getDefaultValue(), getDefaultValue(SessionContext), setDefaultValue(Object)
      • getDescription

        public java.lang.String getDescription()
        Returns:
        the attribute description text localized for the current session language.
      • getDescription

        public java.lang.String getDescription​(SessionContext ctx)
        Parameters:
        ctx - the session context specifying the language to get the localized description for
        Returns:
        the attribute description text localized as spcified by the given session context
      • setDescription

        public void setDescription​(java.lang.String description)
        Changes the attribute description text for the current session languag.
        Parameters:
        description - the new (localized) description
      • setDescription

        public void setDescription​(SessionContext ctx,
                                   java.lang.String description)
        Changes the attribute description text for the specified languag.
        Parameters:
        ctx - the session contex specifying the language to change the description for
        description - the new (localized) description
      • getAllDescriptions

        public java.util.Map getAllDescriptions()
        Returns:
        all localized attribute descriptions as language-to-description map
      • getAllDescriptions

        public java.util.Map getAllDescriptions​(SessionContext ctx)
        Returns:
        all localized attribute descriptions as language-to-description map
      • setAllDescriptions

        public void setAllDescriptions​(java.util.Map descriptions)
        Changes all localized attribute descriptions by providing a language-to-description map.
      • setAllDescriptions

        public void setAllDescriptions​(SessionContext ctx,
                                       java.util.Map descriptions)
        Changes all localized attribute descriptions by providing a language-to-description map.
      • getSelectionOf

        public AttributeDescriptor getSelectionOf()
        Returns the selection-of attribute descriptor.

        Attributes which own a selection-of attribute descriptor must to choose their values from the values readable from the selecion-of attribute.

        Usually selection-of attribute descriptors describe collection attributes so that there are multiple values to chose from.

        Of course the attribute value types have to be compatible.

      • getDatabaseColumn

        public java.lang.String getDatabaseColumn()
        Returns:
        the database column of this attribute or null if the attribute has no persistence representation.
      • setDatabaseColumn

        public void setDatabaseColumn​(java.lang.String col)
        Changes the database column of this attribute.

        This change will be only effective after server restart ! Also note that you have to make sure the column exists since it is not atomatically created due to some database ALTER TABLE limitations.

        Parameters:
        col - the new column name
      • getProposedDatabaseColumn

        public java.lang.String getProposedDatabaseColumn()
        Since all attributes created after initialization are not mapped to a own database column this method provides a column name proposal.

        Such a property attribute can be mapped to a own column as follows:

        • set the column name (as proposed or any other possible name) by setDatabaseColumn(String)
        • shutdown all hybris platform instances
        • create this column manually in the proper database table (use ComposedType.getTable()to get item table name; for localized attributes use table itemtable +'LP' instead)
        • start the hybris platform again
        • the attribute should be read from and stored into the new column now
        Returns:
        the proposed column name
      • getPersistenceClass

        public java.lang.Class getPersistenceClass()
        Returns:
        the java class describing this attribute's persistence type.
        See Also:
        getPersistenceType()
      • getPersistenceType

        public AtomicType getPersistenceType()
        Returns:
        the atomic type describing this attributes persistence type.
        See Also:
        getPersistenceClass()
      • toString

        public java.lang.String toString()
        The string represenation of this attribute descriptor.
        Overrides:
        toString in class Descriptor
        Returns:
        the String representation of this item.
      • toString

        public static java.lang.String toString​(int modifiers)
      • getPersistenceQualifier

        public java.lang.String getPersistenceQualifier()
        If the attribute is backed by a EJB CMP field this method returns the CMP field name. Otherwise null is returned.
      • isRedeclared

        public boolean isRedeclared()
        Tells whether a inherited attribute descriptor has different modifiers and/or a different value type than its super attribute descriptor.

        A redeclared attribute will be included in the XML definition of its type even though it was originally declared in one of its supertypes.

      • getXMLCustomProperties

        protected java.util.Map getXMLCustomProperties()
        Override to add custom properties to this type's xml definition.
      • getXMLDefinition

        public java.lang.String getXMLDefinition()
        Assembles the attribute descriptors XML definition required for items.xml. This definiton will be included in the XML definition of its enclosing type if the attribute has been declarded by it or has been redeclared.
      • exportXMLDefinitionDefaultValue

        protected void exportXMLDefinitionDefaultValue​(org.znerd.xmlenc.XMLOutputter xout)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeDefaultValueTagAtomic

        protected void writeDefaultValueTagAtomic​(org.znerd.xmlenc.XMLOutputter xout,
                                                  java.lang.String atomictype,
                                                  java.lang.String value)
      • checkTypePermission

        public boolean checkTypePermission​(UserRight right)
        Checks the type permission upon this attribute of the current session user.

        Works similar to Item.checkPermission(UserRight)except that the permissions of the enclosing type and super attribute are evaluated in case no permission is set for this attribute.

        The evaluation first checks the enclosing type and in case no permission is defined there too just checks the super attribute recursively.

        Parameters:
        right - the user right to check
      • checkTypePermission

        public boolean checkTypePermission​(Principal p,
                                           UserRight right)
        Checks the type permission upon this attribute of the given principal.

        Works similar to Item.checkPermission(UserRight)except that the permissions of the enclosing type and super attribute are evaluated in case no permission is set for this attribute.

        The evaluation first checks the enclosing type and in case no permission is defined there too just checks the super attribute recursively.

        Parameters:
        p - the principal to check
        right - the user right to check