if ( getType( ) == null ) throw new MetaDataException( new String[]{name}, MetaDataException.DESIGN_EXCEPTION_PROP_TYPE_ERROR );  displayNameID = StringUtil.trimString( displayNameID );    switch ( getTypeCode( ) ) { case IPropertyType.CHOICE_TYPE :      IChoiceSet choiceSet = getChoices( ); if ( choiceSet == null || choiceSet.getChoices( ) == null ) throw new MetaDataException( new String[]{name}, MetaDataException.DESIGN_EXCEPTION_MISSING_PROP_CHOICES ); break;  case IPropertyType.STRUCT_TYPE :    if ( details == null ) throw new MetaDataException( new String[]{name, definedBy( ).getName( )}, MetaDataException.DESIGN_EXCEPTION_MISSING_STRUCT_DEFN );    if ( details instanceof String ) { MetaDataDictionary dd = MetaDataDictionary.getInstance( ); StructureDefn structDefn = (StructureDefn) dd .getStructure( StringUtil .trimString( (String) details ) ); details = structDefn; }  if ( isList( ) ) { StructureListValidator validator = StructureListValidator .getInstance( ); SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn( StructureListValidator.NAME ); triggerDefn.setPropertyName( getName( ) ); triggerDefn.setValidator( validator ); getTriggerDefnSet( ).add( triggerDefn ); } else { StructureValidator validator = StructureValidator .getInstance( ); SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn( StructureValidator.NAME ); triggerDefn.setPropertyName( getName( ) ); triggerDefn.setValidator( validator ); getTriggerDefnSet( ).add( triggerDefn ); } break;  case IPropertyType.ELEMENT_REF_TYPE : buildElementType( ); break;  case IPropertyType.STRUCT_REF_TYPE :    if ( details == null ) throw new MetaDataException( new String[]{name}, MetaDataException.DESIGN_EXCEPTION_MISSING_STRUCT_DEFN );    if ( details instanceof String ) { MetaDataDictionary dd = MetaDataDictionary.getInstance( ); StructureDefn structDefn = (StructureDefn) dd .getStructure( StringUtil .trimString( (String) details ) ); details = structDefn; }    MetaDataDictionary dd = MetaDataDictionary.getInstance( ); IElementDefn report = dd .getElement( ReportDesignConstants.REPORT_DESIGN_ELEMENT ); List properties = report.getProperties( ); boolean isFound = false; for ( int i = 0; i < properties.size( ); i++ ) { IPropertyDefn property = (IPropertyDefn) properties.get( i ); if ( property.getTypeCode( ) == IPropertyType.STRUCT_TYPE ) { if ( property.getStructDefn( ) == getStructDefn( ) ) { isFound = true; break; } } } if ( !isFound ) throw new MetaDataException( new String[]{name}, MetaDataException.DESIGN_EXCEPTION_UNREFERENCABLE_STRUCT_DEFN );  SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn( StructureReferenceValidator.NAME ); triggerDefn.setPropertyName( getName( ) ); triggerDefn.setValidator( StructureReferenceValidator .getInstance( ) ); getTriggerDefnSet( ).add( triggerDefn );  break;  case IPropertyType.LIST_TYPE :    if ( subType == null ) throw new MetaDataException( new String[]{name}, MetaDataException.DESIGN_EXCEPTION_MISSING_SUB_TYPE );    if ( !getSupportedSubTypes( ).contains( subType ) ) throw new MetaDataException( new String[]{name, subType.getName( )}, MetaDataException.DESIGN_EXCEPTION_UNSUPPORTED_SUB_TYPE );    SimpleListValidator validator = SimpleListValidator .getInstance( ); triggerDefn = new SemanticTriggerDefn( SimpleListValidator.NAME ); triggerDefn.setPropertyName( getName( ) ); triggerDefn.setValidator( validator ); getTriggerDefnSet( ).add( triggerDefn );    if ( subType.getTypeCode( ) == IPropertyType.ELEMENT_REF_TYPE ) buildElementType( );  break; }  if ( isValueRequired( ) ) { SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn( ValueRequiredValidator.NAME ); triggerDefn.setPropertyName( getName( ) ); triggerDefn.setValidator( ValueRequiredValidator.getInstance( ) ); getTriggerDefnSet( ).add( triggerDefn ); }   if ( getValueType( ) == EXTENSION_PROPERTY && getTypeCode( ) == IPropertyType.XML_TYPE ) { SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn( ExtensionValidator.NAME ); triggerDefn.setPropertyName( getName( ) ); triggerDefn.setValidator( ExtensionValidator.getInstance( ) ); getTriggerDefnSet( ).add( triggerDefn ); }  if ( getTypeCode( ) != IPropertyType.LIST_TYPE && subType != null ) {   throw new MetaDataException( new String[]{name}, MetaDataException.DESIGN_EXCEPTION_SUB_TYPE_FORBIDDEN ); }  if ( getTypeCode( ) != IPropertyType.STRUCT_TYPE && isList == true ) {   throw new MetaDataException( new String[]{getType( ).getName( )}, MetaDataException.DESIGN_EXCEPTION_INVALID_LIST_TYPE ); }     if ( defaultValue != null ) { try { validateXml( null, defaultValue.toString( ) ); } catch ( PropertyValueException e ) { throw new MetaDataException( new String[]{name, defaultValue.toString( )}, MetaDataException.DESIGN_EXCEPTION_INVALID_DEFAULT_VALUE ); } }    if ( valueValidator != null ) { MetaDataDictionary dict = MetaDataDictionary.getInstance( ); if ( dict.getValueValidator( valueValidator ) == null ) throw new MetaDataException( new String[]{valueValidator, name}, MetaDataException.DESIGN_EXCEPTION_VALIDATOR_NOT_FOUND ); }  getTriggerDefnSet( ).build( );   if ( getTypeCode( ) == IPropertyType.DIMENSION_TYPE || ( getTypeCode( ) == IPropertyType.LIST_TYPE && subType .getTypeCode( ) == IPropertyType.DIMENSION_TYPE ) ) { String defaultUnit = getDefaultUnit( ); if ( !StringUtil.isBlank( defaultUnit ) ) {  IChoiceSet units = getAllowedChoices( ); IChoice choice = units.findChoice( defaultUnit ); if ( choice == null ) { setDefaultUnit( DimensionValue.DEFAULT_UNIT ); throw new MetaDataException( new String[]{getName( ), defaultUnit}, MetaDataException.DESIGN_EXCEPTION_INVALID_UNIT ); } } }
buildTriggerDefnSet( );
	void build( ) throws MetaDataException	{		// Ensure we can find the property type.		if ( getType( ) == null )			throw new MetaDataException( new String[]{name},					MetaDataException.DESIGN_EXCEPTION_PROP_TYPE_ERROR );		displayNameID = StringUtil.trimString( displayNameID );		// Perform type-specific initialization.		switch ( getTypeCode( ) )		{			case IPropertyType.CHOICE_TYPE :				// Build the set of choices. The list is required if this				// property				// is a choice property, and is not allowed otherwise.				IChoiceSet choiceSet = getChoices( );				if ( choiceSet == null || choiceSet.getChoices( ) == null )					throw new MetaDataException(							new String[]{name},							MetaDataException.DESIGN_EXCEPTION_MISSING_PROP_CHOICES );				break;			case IPropertyType.STRUCT_TYPE :				// A structure definition must be provided.				if ( details == null )					throw new MetaDataException(							new String[]{name, definedBy( ).getName( )},							MetaDataException.DESIGN_EXCEPTION_MISSING_STRUCT_DEFN );				// Look up a string name reference.				if ( details instanceof String )				{					MetaDataDictionary dd = MetaDataDictionary.getInstance( );					StructureDefn structDefn = (StructureDefn) dd							.getStructure( StringUtil									.trimString( (String) details ) );					details = structDefn;				}				if ( isList( ) )				{					StructureListValidator validator = StructureListValidator							.getInstance( );					SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn(							StructureListValidator.NAME );					triggerDefn.setPropertyName( getName( ) );					triggerDefn.setValidator( validator );					getTriggerDefnSet( ).add( triggerDefn );				}				else				{					StructureValidator validator = StructureValidator							.getInstance( );					SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn(							StructureValidator.NAME );					triggerDefn.setPropertyName( getName( ) );					triggerDefn.setValidator( validator );					getTriggerDefnSet( ).add( triggerDefn );				}				break;			case IPropertyType.ELEMENT_REF_TYPE :				buildElementType( );				break;			case IPropertyType.STRUCT_REF_TYPE :				// A structure definition must be provided.				if ( details == null )					throw new MetaDataException(							new String[]{name},							MetaDataException.DESIGN_EXCEPTION_MISSING_STRUCT_DEFN );				// Look up a string name reference.				if ( details instanceof String )				{					MetaDataDictionary dd = MetaDataDictionary.getInstance( );					StructureDefn structDefn = (StructureDefn) dd							.getStructure( StringUtil									.trimString( (String) details ) );					details = structDefn;				}				// the structure must be defined in the ReportDesign				MetaDataDictionary dd = MetaDataDictionary.getInstance( );				IElementDefn report = dd						.getElement( ReportDesignConstants.REPORT_DESIGN_ELEMENT );				List properties = report.getProperties( );				boolean isFound = false;				for ( int i = 0; i < properties.size( ); i++ )				{					IPropertyDefn property = (IPropertyDefn) properties.get( i );					if ( property.getTypeCode( ) == IPropertyType.STRUCT_TYPE )					{						if ( property.getStructDefn( ) == getStructDefn( ) )						{							isFound = true;							break;						}					}				}				if ( !isFound )					throw new MetaDataException(							new String[]{name},							MetaDataException.DESIGN_EXCEPTION_UNREFERENCABLE_STRUCT_DEFN );				SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn(						StructureReferenceValidator.NAME );				triggerDefn.setPropertyName( getName( ) );				triggerDefn.setValidator( StructureReferenceValidator						.getInstance( ) );				getTriggerDefnSet( ).add( triggerDefn );				break;			case IPropertyType.LIST_TYPE :				// list property must provide the subtype				if ( subType == null )					throw new MetaDataException( new String[]{name},							MetaDataException.DESIGN_EXCEPTION_MISSING_SUB_TYPE );				// check the subtype, not all simple types are supported				if ( !getSupportedSubTypes( ).contains( subType ) )					throw new MetaDataException(							new String[]{name, subType.getName( )},							MetaDataException.DESIGN_EXCEPTION_UNSUPPORTED_SUB_TYPE );				// add the simple list validator				// TODO exclude the style property				SimpleListValidator validator = SimpleListValidator						.getInstance( );				triggerDefn = new SemanticTriggerDefn( SimpleListValidator.NAME );				triggerDefn.setPropertyName( getName( ) );				triggerDefn.setValidator( validator );				getTriggerDefnSet( ).add( triggerDefn );				// sub-type is element, then do some checks for it				if ( subType.getTypeCode( ) == IPropertyType.ELEMENT_REF_TYPE )					buildElementType( );				break;		}		if ( isValueRequired( ) )		{			SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn(					ValueRequiredValidator.NAME );			triggerDefn.setPropertyName( getName( ) );			triggerDefn.setValidator( ValueRequiredValidator.getInstance( ) );			getTriggerDefnSet( ).add( triggerDefn );		}		// add extension validator on exteion xml property		if ( getValueType( ) == EXTENSION_PROPERTY				&& getTypeCode( ) == IPropertyType.XML_TYPE )		{			SemanticTriggerDefn triggerDefn = new SemanticTriggerDefn(					ExtensionValidator.NAME );			triggerDefn.setPropertyName( getName( ) );			triggerDefn.setValidator( ExtensionValidator.getInstance( ) );			getTriggerDefnSet( ).add( triggerDefn );		}		if ( getTypeCode( ) != IPropertyType.LIST_TYPE && subType != null )		{			// only when the type is list, the subtype is set			throw new MetaDataException( new String[]{name},					MetaDataException.DESIGN_EXCEPTION_SUB_TYPE_FORBIDDEN );		}		if ( getTypeCode( ) != IPropertyType.STRUCT_TYPE && isList == true )		{			// only support list of structures.			throw new MetaDataException( new String[]{getType( ).getName( )},					MetaDataException.DESIGN_EXCEPTION_INVALID_LIST_TYPE );		}		// if the property has a defalut value, validate it again. At this time,		// it will be validated against the allowed choices.		if ( defaultValue != null )		{			try			{				validateXml( null, defaultValue.toString( ) );			}			catch ( PropertyValueException e )			{				throw new MetaDataException(						new String[]{name, defaultValue.toString( )},						MetaDataException.DESIGN_EXCEPTION_INVALID_DEFAULT_VALUE );			}		}		// ensure that the validator is defined in the dictionary.		if ( valueValidator != null )		{			MetaDataDictionary dict = MetaDataDictionary.getInstance( );			if ( dict.getValueValidator( valueValidator ) == null )				throw new MetaDataException(						new String[]{valueValidator, name},						MetaDataException.DESIGN_EXCEPTION_VALIDATOR_NOT_FOUND );		}		getTriggerDefnSet( ).build( );		// default unit check		if ( getTypeCode( ) == IPropertyType.DIMENSION_TYPE				|| ( getTypeCode( ) == IPropertyType.LIST_TYPE && subType						.getTypeCode( ) == IPropertyType.DIMENSION_TYPE ) )		{			String defaultUnit = getDefaultUnit( );			if ( !StringUtil.isBlank( defaultUnit ) )			{				IChoiceSet units = getAllowedChoices( );				IChoice choice = units.findChoice( defaultUnit );				if ( choice == null )				{					setDefaultUnit( DimensionValue.DEFAULT_UNIT );					throw new MetaDataException( new String[]{getName( ),							defaultUnit},							MetaDataException.DESIGN_EXCEPTION_INVALID_UNIT );				}			}		}	}