Class ComposedType

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable
    Direct Known Subclasses:
    EnumerationType, GeneratedCMSComponentType, GeneratedCMSPageType, GeneratedRestrictionType, GeneratedVariantType, RelationType, ViewType

    public class ComposedType
    extends Type
    The base type describing jalo item instances. The name composed type refers to AtomicType which describes just single values whereas composed types describe objects which consists of many values. Inside the hybris platform normally these are Items.

    Composed types holdAttributeDescriptors which describes a single field of the item. Attribute descriptors are inherited from the declaring type to all its subtypes. Subtypes may change them afterwards locally which does not affect the original attribute descriptor belonging to the declaring type (though type compatibility checks are made).

    Additionally non-abstract composed types show all persistence information belonging to the item:

    • database table
    • dump property database table
    • ejb jndi name
    • ejb bean typecode

    These types may be used for creating new item instances generically without having to call their actual managers via newInstance(Map) . This provides a way of creating and setting additionally data inside one step (which normally cannot be done using the manager).

    Composed type can be retrieved byjalo class or code .

    An essential use case of composed types are searches via FlexibleSearch:

     ComposedType myType = TypeManager.getInstance().getComposedType(MyClass.class);
     List<MyClass> myItems = jaloSession.getFlexibleSearch().search(//
                    "SELECT {" + Item.PK + "} FROM {" + myType.getCode() + "}", //
                    Collections.EMPTY_MAP, //
                    MyClass.class).getResult();
     
    See Also:
    Serialized Form
    • Field Detail

      • SUPERTYPE

        public static final java.lang.String SUPERTYPE
        The supertype attribute qualifier constant.
      • SUBTYPES

        public static final java.lang.String SUBTYPES
        The subtypes attribute qualifier constant.
      • DECLAREDATTRIBUTEDESCRIPTORS

        public static final java.lang.String DECLAREDATTRIBUTEDESCRIPTORS
        The declared attribute descriptors attribute qualifier constant.
      • INHERITEDATTRIBUTEDESCRIPTORS

        public static final java.lang.String INHERITEDATTRIBUTEDESCRIPTORS
        The inherited attribute descriptors attribute qualifier constant.
      • ATTRIBUTEDESCRIPTORS

        public static final java.lang.String ATTRIBUTEDESCRIPTORS
        The (all) attribute descriptors attribute qualifier constant.
      • JALOCLASS

        public static final java.lang.String JALOCLASS
        The jalo class attribute qualifier constant.
      • INHERITANCEPATH

        protected static final java.lang.String INHERITANCEPATH
        Internal attribute The inheritance path.
      • SINGLETON

        public static final java.lang.String SINGLETON
        The singleton attribute qualifier constant.
      • JALOONLY

        public static final java.lang.String JALOONLY
        The jalo-only attribute qualifier constant.
      • DYNAMIC

        public static final java.lang.String DYNAMIC
        The dynami attribute qualifier constant.
      • ABSTRACT

        public static final java.lang.String ABSTRACT
        The abstract attribute qualifier constant.
      • TABLE

        public static final java.lang.String TABLE
        The database table attribute qualifier constant.
      • DUMPPROPERTYTABLE

        public static final java.lang.String DUMPPROPERTYTABLE
        The dump property table attribute qualifier constant.
      • JNDINAME

        public static final java.lang.String JNDINAME
        The jndi name attribute qualifier constant.
      • ALLSUPERTYPES

        public static final java.lang.String ALLSUPERTYPES
        The all supertypes attribute qualifier constant.
      • ALLSUBTYPES

        public static final java.lang.String ALLSUBTYPES
        The all subtypes attribute qualifier constant.
    • Constructor Detail

      • ComposedType

        public ComposedType()
    • Method Detail

      • newInstance

        public static <E extends Item> E newInstance​(SessionContext ctx,
                                                     java.lang.Class jaloClass,
                                                     java.lang.Object... params)
                                              throws JaloGenericCreationException,
                                                     JaloAbstractTypeException,
                                                     JaloItemNotFoundException
        Convenience method for creating typed instances of a given composed type. This method does not take a parameter map but allows to pass parameters as value list.

        Use as follows:

         Product p = ComposedType.newInstance(ctx, Product.class, Product.CODE, "myCode", Product.UNIT, unit);
         

        In other words: make sure the parameter list always contains one attribute qualifer followed by its value etc. Otherwise an exception will be raised.

        Parameters:
        ctx - the session context
        jaloClass - the jalo class which specifies the composed type
        params - the attribute values as list of qualifier, value, ...
        Returns:
        the new item
        Throws:
        JaloGenericCreationException - in case something goes wrong during creation
        JaloAbstractTypeException - if the actual composed type is abstract
        JaloItemNotFoundException - if the specified class does not belong to any composed type
      • newInstance

        public static <E extends Item> E newInstance​(SessionContext ctx,
                                                     java.lang.String typeCode,
                                                     java.lang.Object... params)
                                              throws JaloGenericCreationException,
                                                     JaloAbstractTypeException,
                                                     JaloItemNotFoundException
        Convenience method for creating typed instances of a given composed type.This method does not take a parameter map but allows to pass parameters as value list.

        Use as follows:

         Product p = ComposedType.newInstance(ctx, Product.class, Product.CODE, "myCode", Product.UNIT, unit);
         

        In other words: make sure the parameter list always contains one attribute qualifer followed by its value etc. Otherwise an exception will be raised.

        Parameters:
        ctx - the session context
        typeCode - the code which specifies the composed type
        params - the attribute value list
        Returns:
        the new item
        Throws:
        JaloGenericCreationException - in case something goes wrong during creation
        JaloAbstractTypeException - if the actual composed type is abstract
        JaloItemNotFoundException - if the specified code does not belong to any composed type
      • getNonInitialAttributes

        protected Item.ItemAttributeMap getNonInitialAttributes​(SessionContext ctx,
                                                                Item.ItemAttributeMap allAttributes)
        Cuts SUPERTYPE and Type.CODE from the attribute map since these values are already set actual item during creation.
        Overrides:
        getNonInitialAttributes in class Item
        Parameters:
        ctx - session context with language = NULL
        allAttributes - a ItemAttributeMap contaning attribute values.
        Returns:
        a ItemAttributeMap containing all attribute values, which belong to non-initial attributes.
      • getTable

        public java.lang.String getTable()
        Returns:
        the name of the database table assoziated with this type. for abstract types this name may be NULL.
      • getDumpPropertyTable

        public java.lang.String getDumpPropertyTable()
        Returns the name of the dump property table. Any untyped property attribute is read and written from and into this table.

        Typed property attributes are attributes declared in items.xml and so created during system initialization. Any other property attribute which was created afterwards will store its values inside the dump table just like properties which do not have an attribute at all.

      • getJNDIName

        public java.lang.String getJNDIName()
        Returns:
        the JNDI name of the assoziated item EJB. since abstract types normally dont have deployed item EJB's this may return NULL for such types.
      • getItemTypeCode

        public int getItemTypeCode()
        Returns:
        the typecode of the assoziated item EJB. abstract types doesnt have such typecode, so 0 will be returned.
      • getAllConcreteItemTypeCodes

        public java.util.Set<java.lang.Integer> getAllConcreteItemTypeCodes()
        Since:
        2.10
      • getJaloClass

        public java.lang.Class getJaloClass()
        Returns:
        the jalo class object of the item defined by this type. if this type doesnt have a own jalo class the supertype is used.
      • getDeclaredJaloClass

        public java.lang.Class getDeclaredJaloClass()
        Returns:
        the jalo class which has been declared for this type. if no class has been declared null is returned.
      • setJaloClass

        public void setJaloClass​(java.lang.Class newOne)
        changes this type's jalo class
        Parameters:
        newOne - the new jalo class ; setting to null means using the supertype jalo class
      • getInheritedAttributeDescriptors

        public java.util.Set<AttributeDescriptor> getInheritedAttributeDescriptors()
        Returns all attribute descriptors of this composedy type which have been declared by one of its supertype and are inherited (copied) for this type.

        Please note that these attribute descriptors belong to this type exclusively since it has been copied from the direct supertype's same attribute descriptor.

        See Also:
        getDeclaredAttributeDescriptor(String), getAttributeDescriptors()
      • getAllSuperTypes

        public java.util.List<ComposedType> getAllSuperTypes()
        Returns the complete supertype list of this type containing the top-most type at the end of the list and its direct supertype at first.
        See Also:
        getSuperType()
      • getInheritancePathString

        protected java.lang.String getInheritancePathString()
        Returns the internal representation if this types supertype list. Dont use directly!
      • getAllSubTypes

        public java.util.Set<ComposedType> getAllSubTypes()
        Returns all subtypes of this type. This includes its direct subtypes, their subtypes, etc.
        See Also:
        getSubTypes()
      • getInitialAttributeDescriptors

        public java.util.Set getInitialAttributeDescriptors()
        Returns all attribute descriptors of this type which are marked as being initial.

        Initial attributes are normally non-writable attributes intented to be set during item creation only. Therefore having initial and writable attributed doesnt make much sense.

      • _sortAttributesByQualifier

        protected void _sortAttributesByQualifier​(java.util.List<AttributeDescriptor> lst)
      • getDeclaredAttributeDescriptors

        public java.util.Set getDeclaredAttributeDescriptors()
        Returns all attributes which are declared by this type.

        The type may own additional attribute descriptors which are not declared by itself but one of its supertypes.

        See Also:
        getInheritedAttributeDescriptors(), getAttributeDescriptors()
      • getPartOfAutoRemovalAttributeDescriptors

        public java.util.Set<AttributeDescriptor> getPartOfAutoRemovalAttributeDescriptors()
      • getAttributeDescriptorsIncludingPrivate

        public java.util.Set<AttributeDescriptor> getAttributeDescriptorsIncludingPrivate()
        Returns all attribute descriptors of this type including all marked as private.
      • getAttributeDescriptorsIncludingPrivate

        public java.util.Set<AttributeDescriptor> getAttributeDescriptorsIncludingPrivate​(java.util.Collection<java.lang.String> qualifiers)
      • getAttributeDescriptorIncludingPrivate

        public AttributeDescriptor getAttributeDescriptorIncludingPrivate​(java.lang.String qualifier)
                                                                   throws JaloItemNotFoundException
        Returns a declared or inherited attribute descriptor of this type even if is marked as private.
        Parameters:
        qualifier - the attribute descriptor qualifier
        Throws:
        JaloItemNotFoundException
      • getDeclaredAttributeDescriptor

        public AttributeDescriptor getDeclaredAttributeDescriptor​(java.lang.String qualifier)
                                                           throws JaloItemNotFoundException
        Returns a specific declared attribute descriptor.
        Parameters:
        qualifier - the attribute qualifier (case insensitive)
        Throws:
        JaloItemNotFoundException - in case no such attribute descriptor exists
      • getAttributeDescriptor

        public AttributeDescriptor getAttributeDescriptor​(java.lang.String qualifier)
                                                   throws JaloItemNotFoundException
        Returns a specific attribute descriptor regardless of whether it has been declared by this type or not.
        Parameters:
        qualifier - the attribute qualifier (case insensitive)
        Throws:
        JaloItemNotFoundException - in case no such attribute descriptor exists
      • hasAttribute

        public boolean hasAttribute​(java.lang.String qualifier)
                             throws JaloItemNotFoundException
        Returns true of the attribute with the given qualifier exist in this composed type
        Parameters:
        qualifier - the attribute qualifier (case insensitive)
        Throws:
        JaloItemNotFoundException
      • getEveryAttributeDescriptor

        @Deprecated
        public AttributeDescriptor getEveryAttributeDescriptor​(java.lang.String qualifier)
                                                        throws JaloItemNotFoundException
        Deprecated.
        Returns a specific attribute descriptor regardless of whether it has been declared by this type or not. Additionally this method will also find attribute descriptors marked as private.
        Parameters:
        qualifier - the attribute qualifier (case insensitive)
        Throws:
        JaloItemNotFoundException - in case no such attribute descriptor exists
      • getRelations

        public java.util.Set<RelationType> getRelations()
        Returns all relations this type is involved in. These are all relations which define a RelationDescriptor for this type.
      • newInstance

        public Item newInstance​(java.util.Map attributeAssignment)
                         throws JaloGenericCreationException,
                                JaloAbstractTypeException
        Creates a new instance of the Jalo Item described by this type. The whole creation can be considered as being atomic - if any error was raised during creation all changes will not take effect.

        Please refer to the documentation regarding transaction support for the installation plaform and database to ensure if this behaviour can be guaranteed!

        An example:

         // get the desired type
         ComposedType currencyType = jaloSession.getTypeManager().getComposedType(Currency.class);
        
         // fill attribute value map
         Map attributes = new HashMap();
         attibutes.put(C2LItem.ISOCODE, "DE");
         attibutes.put(Currency.DIGITS, new Integer(2));
         attibutes.put(C2LItem.SYMBOL, "EUR");
        
         // create item instance
         Currency newOne = null;
         try
         {
                newOne = (Currency) currencyType.newInstance(attributes);
         }
         catch (JaloGenericCreationException e)
         {
                Throwable cause = e.getCause();
                // check expected exceptions
                if (cause instanceof ConsistencyCheckException)
            {
                        System.err.println("duplicate ISO code : " + cause);
            }
                // report unexpected exceptions
                else
            {
                        throw new JaloSystemException(e);
            }
         }
         
        Parameters:
        attributeAssignment - a map containing all attribute values required for the specific item during creation - optional attribute may be passed as well here
        Throws:
        JaloGenericCreationException - in case any business eaxception was raised during creation
        JaloAbstractTypeException - in case the type is abstract, means there cannot exist instances of it
      • newInstance

        public Item newInstance​(SessionContext ctx,
                                java.util.Map attributeAssignment)
                         throws JaloGenericCreationException,
                                JaloAbstractTypeException
        Creates a new instance of the Jalo Item described by this type. The whole creation can be considered as being atomic - if any error was raised during creation all changes will not take effect.

        Please refer to the documentation regarding transaction support for the installation plaform and database to ensure if this behaviour can be guaranteed!

        An example:

         // get the desired type
         ComposedType currencyType = jaloSession.getTypeManager().getComposedType(Currency.class);
        
         // fill attribute value map
         Map attributes = new HashMap();
         attibutes.put(C2LItem.ISOCODE, "EUR");
         attibutes.put(Currency.DIGITS, new Integer(2));
         attibutes.put(C2LItem.SYMBOL, "EUR");
         // localized attributes too
         attibutes.put(C2LItem.NAME, "Deutsch");
        
         // create item instance
         Currency newOne = null;
         try
         {
                SessionContext deCtx = jaloSession.createSessionContext();
                deCtx.setLanguage(jaloSession.getC2LManager().getLanguageByIsoCode("de"));
                newOne = (Currency) currencyType.newInstance(deCtx, attributes);
         }
         catch (JaloGenericCreationException e)
         {
                Throwable cause = e.getCause();
                // check expected exceptions
                if (cause instanceof ConsistencyCheckException)
            {
                        System.err.println("duplicate ISO code : " + cause);
            }
                // report unexpected exceptions
                else
            {
                        throw new JaloSystemException(e);
            }
         }
         
        Parameters:
        ctx - the session context which the new item should be created within - define language of localized values here
        attributeAssignment - a map containing all attribute values required for the specific item during creation - optional attribute may be passed as well here
        Throws:
        JaloGenericCreationException - in case any business eaxception was raised during creation
        JaloAbstractTypeException - in case the type is abstract, means there cannot exist instances of it
      • getAllDefaultValues

        public java.util.Map getAllDefaultValues()
        Returns all default values of this type. The map contains mapping from attribute qualifiers to their default values unless the attribute do not own a default value or is not writable.

        The returned map works case insensitive.

        See Also:
        getAllDefaultValues(SessionContext), AttributeDescriptor.getDefaultValue()
      • getAllDefaultValues

        public java.util.Map getAllDefaultValues​(SessionContext ctx)
        Returns all default values of this type. The map contains mapping from attribute qualifiers to their default values unless the attribute do not own a default value or is not writable.

        The returned map works case insensitive.

        See Also:
        getAllDefaultValues(), AttributeDescriptor.getDefaultValue()
      • getDefaultValues

        public java.util.Map getDefaultValues​(java.util.Set fdCodes)
                                       throws JaloItemNotFoundException
        Returns the default values for a specified set of attributes. The map contains mapping from attribute qualifiers to their default values unless the attribute do not own a default value or is not writable.

        The returned map works case insensitive.

        Parameters:
        fdCodes - a set of attribute descriptor qualifiers
        Throws:
        JaloItemNotFoundException - in case of missing attribute for one specified qualifer
      • getAllInstances

        public java.util.Set getAllInstances()
        Returns all instances of this type. Since search restrictions may apply this includes all jalo items which are visible to the current session user.
      • createJaloOnlyInstance

        protected Item createJaloOnlyInstance​(SessionContext ctx,
                                              java.util.Map attributes)
      • getAllInstances

        public java.util.Set getAllInstances​(SessionContext ctx)
        Returns all instances of this type. Since search restrictions may apply this includes all jalo items which are visible to the current session user.
      • getAllInstancesCount

        public long getAllInstancesCount()
        Returns the number of instances of this type. Since search restrictions may apply to the current user this will show the number of visible instances only.
      • isSingleton

        public boolean isSingleton()
        Tells whether or not this type describes at most one instance or not.
        Returns:
        true if this type describes at most one instance
      • isJaloOnly

        public boolean isJaloOnly()
        Tells whether this type is not really an item but just a jalo class which access all the attributes.
        NOTE: This attribute is applicable on the singleton type only!
        Returns:
        true if this type is not really an item but just a jalo class which access all the attributes
      • isDynamic

        public boolean isDynamic()
        Tells whether this type is dynamic.
        NOTE: This attribute is applicable on the enumeration type only!
        Returns:
        true if this type is changeable at runtime
      • isAbstract

        public boolean isAbstract()
        Tells whether this type may have instances or not.
        Returns:
        true if the type cannot have instances.
      • isJaloClassAbstract

        protected boolean isJaloClassAbstract()
      • setSingleton

        public void setSingleton​(boolean isSingleton)
                          throws JaloInvalidParameterException
        Changes this types singleton status.
        Parameters:
        isSingleton - if true the type is marked as having just one instance
        Throws:
        JaloInvalidParameterException - in case a type with more than one instance is tried to mark as singleton.
      • setJaloOnly

        public void setJaloOnly​(boolean isJaloOnly)
                         throws JaloInvalidParameterException
        Changes this types jalo-only status.
        NOTE: This attribute is applicable on the singleton type only!
        Parameters:
        isJaloOnly - if true the instance of this type is not really an item but just a jalo class which access all the attributes
        Throws:
        JaloInvalidParameterException
      • getXMLCustomProperties

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

        public java.lang.String getXMLDefinition()
        Returns the XML definition text for declaring this type in items.xml. This method will show the declaration to put inside the items.xml of the extension which this type belongs to.

        Any changes made to this type by means of other extensions items.xml will not show up here - use getXMLDefinition(String) to get them.

        Specified by:
        getXMLDefinition in class Type
        See Also:
        getXMLDefinition(String)
      • getXMLDefinition

        public java.lang.String getXMLDefinition​(java.lang.String forExtension)
        Returns the XML definition text for a specified extension. This will include any attributes added by this extensions items.xml.
        Parameters:
        forExtension -
        See Also:
        getXMLDefinition()
      • exportXMLDefinition

        public java.lang.String exportXMLDefinition​(org.znerd.xmlenc.XMLOutputter xout,
                                                    java.lang.String forExtension)
      • hasOwnDeployment

        public final boolean hasOwnDeployment()
        Tells whether this type has defined his own deployment.
        Returns:
        true if this type has own deployment
      • isAssignableFrom

        public boolean isAssignableFrom​(Type type)
        Checks whether this type is assignable from the specified type. This is the case if this type is the same or supertype of the specified type and this type's jalo class is assignable from the specified type's jalo class.
        Specified by:
        isAssignableFrom in class Type
        Parameters:
        type - the type to check assignability for
      • isSameOrSuperTypeOf

        protected boolean isSameOrSuperTypeOf​(ComposedType type)
        Tests if this type is the same or supertype of the specified type.
      • isInstance

        public boolean isInstance​(java.lang.Object o)
        Tests if the given object is an item instance of this type.
        Specified by:
        isInstance in class Type
        Parameters:
        o - the object to be checked.
      • toString

        public java.lang.String toString()
        Returns the string representation of this type including its code, supertype and its declared attribute descriptors. Use carefully since this method may become quite costly putting together all attributes.
        Overrides:
        toString in class Type
        Returns:
        the String representation of this item.
      • setTypeSearchSessionContex

        @Deprecated
        protected boolean setTypeSearchSessionContex()
        Deprecated.
        since 5.0.1
        Internal - dont use.
      • unsetTypeSearchContext

        @Deprecated
        protected void unsetTypeSearchContext​(boolean useLocal)
        Deprecated.
        since 5.0.1
        Internal - dont use.
      • checkTypePermission

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

        works similar to Item.checkPermission(UserRight) except that supertype permissions are evaluated in case no permission is set for this type.

        Parameters:
        right - the user right to check
        Returns:
        true if the current session user has the permission on the specified UserRight
      • checkTypePermission

        public boolean checkTypePermission​(Principal p,
                                           UserRight right)
        Checks the type permission of a given user.

        works similar to Item.checkPermission(UserRight) except that supertype permissions are evaluated in case no permission is set for this type.

        Parameters:
        p - the principal to check
        right - the user right to check
        Returns:
        true if the specified Principal has the permission on the specified UserRight
      • getSingletonInstance

        public Item getSingletonInstance()
        Gets the singleton instance of this type if the type is marked as singleton. Tries to get the existing instance, if not existent a new one will be created.
        Returns:
        the singleton instance of this type
        Throws:
        JaloInvalidParameterException - type is not marked as singleton type
        JaloSystemException - error while instance creation
        Since:
        3.0