예제 #1
0
        /// <summary>
        /// Determine if we'll render this or not
        /// </summary>
        public static string WillRender(Enumeration enu)
        {
            if (!String.IsNullOrEmpty(Datatypes.GetBuiltinVocabulary(enu.Name)))
            {
                return(enu.Name);
            }

            // This will check the literal count against bound vocab sets
            // if the enu is currently a concept domain
            if (enu is ConceptDomain && (enu as ConceptDomain).ContextBinding != null && (enu as ConceptDomain).ContextBinding.Count == 1)
            {
                enu = (enu as ConceptDomain).ContextBinding[0];
            }
            else if (enu is ConceptDomain && (enu as ConceptDomain).ContextBinding != null && (enu as ConceptDomain).ContextBinding.Count > 1) // HACK: If there is more than one context binding create a new value set, clear the binding and then re-bind
            {
                // Create the VS
                ValueSet vsNew = new ValueSet()
                {
                    Name          = String.Format("{0}AutoGen", enu.Name),
                    BusinessName  = enu.BusinessName,
                    Documentation = new Documentation()
                    {
                        Description = new List <string>(new string[] {
                            String.Format("Value set has automatically been generated by GPMR to allow binding to ConceptDomain '{0}'", enu.Name)
                        }),
                        Rationale = new List <string>()
                    },
                    Id         = enu.Id,
                    Literals   = new List <Enumeration.EnumerationValue>(),
                    MemberOf   = enu.MemberOf,
                    OwnerRealm = enu.OwnerRealm
                };

                // Add literals and documentation
                vsNew.Documentation.Rationale.Add(String.Format("GPMR can normally only redirect context bindings from a concept domain if only 1 is present, however this concept domain has '{0}' present. This value set is a union of content from:", (enu as ConceptDomain).ContextBinding.Count));
                foreach (Enumeration vs in (enu as ConceptDomain).ContextBinding)
                {
                    // If any of the context binding codes are not to be rendered do not render any of them
                    if (WillRender(vs) == String.Empty)
                    {
                        return(String.Empty);
                    }

                    // Output rationale
                    vsNew.Documentation.Rationale.Add(String.Format("<p>- {0} ({1})</p>", vs.Name, vs.EnumerationType));
                    // Add literals
                    vsNew.Literals.AddRange(vs.GetEnumeratedLiterals());
                }

                // Now fire parse to add to the domain
                vsNew.FireParsed();

                // Replace the context bindings
                (enu as ConceptDomain).ContextBinding.Clear();
                (enu as ConceptDomain).ContextBinding.Add(vsNew);

                // redirect
                enu = vsNew;
            }
            else if (enu is ConceptDomain)
            {
                return(String.Empty);
            }

            // Partial enumerations or suppressed enumerations are not to be included
            if (enu.IsPartial && !RimbaJavaRenderer.RenderPartials)
            {
                return(String.Empty);
            }

            // Too big
            if (enu.GetEnumeratedLiterals().Count > RimbaJavaRenderer.MaxLiterals)
            {
                return(String.Empty);
            }

            // Already has a preferred name?
            if (enu.Annotations != null && enu.Annotations.Exists(o => o is RenderAsAnnotation))
            {
                return((enu.Annotations.Find(o => o is RenderAsAnnotation) as RenderAsAnnotation).RenderName);
            }

            // Already being used
            if (m_markedForUse.Exists(o => o.Name == enu.Name && o.GetType() == enu.GetType()))
            {
                return(enu.Name);
            }

            string name = enu.Name;

            if (enu.GetEnumeratedLiterals().Count > 0 && enu.GetEnumeratedLiterals().FindAll(l => !l.Annotations.Exists(o => o is SuppressBrowseAnnotation)).Count > 0 &&
                (RimbaJavaRenderer.GenerateVocab || (!RimbaJavaRenderer.GenerateVocab && enu is ValueSet)))
            {
                // Name collision? Resolve
                if (enu.MemberOf.Find(o => o.Name == enu.Name && o.GetType() != enu.GetType() &&
                                      !(o is ConceptDomain)) != null)
                {
                    if (m_markedForUse.Exists(o => o.Name == enu.Name && o.GetType() != enu.GetType()))
                    {
                        name = String.Format("{0}1", enu.Name);
                        if (enu.Annotations == null)
                        {
                            enu.Annotations = new List <Annotation>();
                        }
                        enu.Annotations.Add(new RenderAsAnnotation()
                        {
                            RenderName = name
                        });
                    }
                }
                return(name); // don't process
            }
            return(String.Empty);
        }