コード例 #1
0
        public static string PropertyTitle(this IMemberSpec memberSpec, INakedObjectAdapter nakedObjectAdapter, INakedObjectManager manager, ISession session, IObjectPersistor persistor)
        {
            if (nakedObjectAdapter == null)
            {
                return("");
            }

            string text  = null;
            var    regex = memberSpec.GetFacet <IRegExFacet>();

            if (regex != null)
            {
                text = regex.Format(nakedObjectAdapter.TitleString());
            }

            var mask = memberSpec.GetFacet <IMaskFacet>();

            if (mask != null)
            {
                var title = memberSpec.ReturnSpec.GetFacet <ITitleFacet>();
                text = title.GetTitleWithMask(mask.Value, nakedObjectAdapter, manager, session, persistor);
            }

            return(text ?? nakedObjectAdapter.TitleString());
        }
コード例 #2
0
 public static string PropertyTitle(this IMemberSpec memberSpec, INakedObjectAdapter nakedObjectAdapter, INakedObjectManager manager) {
     if (nakedObjectAdapter == null) {
         return "";
     }
     string text = null;
     var regex = memberSpec.GetFacet<IRegExFacet>();
     if (regex != null) {
         text = regex.Format(nakedObjectAdapter.TitleString());
     }
     var mask = memberSpec.GetFacet<IMaskFacet>();
     if (mask != null) {
         var title = memberSpec.ReturnSpec.GetFacet<ITitleFacet>();
         text = title.GetTitleWithMask(mask.Value, nakedObjectAdapter, manager);
     }
     return text ?? nakedObjectAdapter.TitleString();
 }
コード例 #3
0
        public string Invalidates(IInteractionContext ic)
        {
            INakedObjectAdapter proposedArgument = ic.ProposedArgument;

            if (DoesNotMatch(proposedArgument))
            {
                return(string.Format(Resources.NakedObjects.MaskMismatch, proposedArgument.TitleString(), Value));
            }
            return(null);
        }
コード例 #4
0
        public string Invalidates(IInteractionContext ic)
        {
            INakedObjectAdapter proposedArgument = ic.ProposedArgument;

            if (proposedArgument == null)
            {
                return(null);
            }
            string titleString = proposedArgument.TitleString();

            if (!DoesNotMatch(titleString))
            {
                return(null);
            }

            return(failureMessage ?? Resources.NakedObjects.InvalidEntry);
        }
コード例 #5
0
        public Place ObjectToElement(INakedObjectAdapter nakedObjectAdapter) {
            Log.Debug("objectToElement(" + DoLog("object", nakedObjectAdapter) + ")");

            var nos = (IObjectSpec) nakedObjectAdapter.Spec;

            Log.Debug("objectToElement(NO): create element and nof:title");
            XElement element = Schema.CreateElement(XmlDocument, nos.ShortName, nos.FullName, nos.SingularName, nos.PluralName);
            NofMetaModel.AppendNofTitle(element, nakedObjectAdapter.TitleString());

            Log.Debug("objectToElement(NO): create XS element for NOF class");
            XElement xsElement = Schema.CreateXsElementForNofClass(XsdDocument, element, topLevelElementWritten);

            // hack: every element in the XSD schema apart from first needs minimum cardinality setting.
            topLevelElementWritten = true;

            var place = new Place(nakedObjectAdapter, element);

            NofMetaModel.SetAttributesForClass(element, OidOrHashCode(nakedObjectAdapter));

            IAssociationSpec[] fields = nos.Properties;
            Log.Debug("objectToElement(NO): processing fields");

            var seenFields = new List<string>();

            foreach (IAssociationSpec field in fields) {
                string fieldName = field.Id;

                Log.Debug("objectToElement(NO): " + DoLog("field", fieldName));

                // Skip field if we have seen the name already
                // This is a workaround for getLastActivity(). This method exists
                // in AbstractNakedObject, but is not (at some level) being picked up
                // by the dot-net reflector as a property. On the other hand it does
                // exist as a field in the meta model (NakedObjectSpecification).
                //
                // Now, to re-expose the lastactivity field for .Net, a deriveLastActivity()
                // has been added to BusinessObject. This caused another field ofthe
                // same name, ultimately breaking the XSD.

                if (seenFields.Contains(fieldName)) {
                    Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " SKIPPED");
                    continue;
                }
                seenFields.Add(fieldName);

                XNamespace ns = Schema.GetUri();

                var xmlFieldElement = new XElement(ns + fieldName);

                XElement xsdFieldElement;
                var oneToOneAssociation = field as IOneToOneAssociationSpec;
                var oneToManyAssociation = field as IOneToManyAssociationSpec;

                if (field.ReturnSpec.IsParseable && oneToOneAssociation != null) {
                    Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is value");

                    IObjectSpec fieldNos = field.ReturnSpec;
                    // skip fields of type XmlValue
                    if (fieldNos != null &&
                        fieldNos.FullName != null &&
                        fieldNos.FullName.EndsWith("XmlValue")) {
                        continue;
                    }

                    XElement xmlValueElement = xmlFieldElement; // more meaningful locally scoped name

                    try {
                        INakedObjectAdapter value = oneToOneAssociation.GetNakedObject(nakedObjectAdapter);

                        // a null value would be a programming error, but we protect
                        // against it anyway
                        if (value == null) {
                            continue;
                        }

                        ITypeSpec valueNos = value.Spec;

                        // XML
                        NofMetaModel.SetAttributesForValue(xmlValueElement, valueNos.ShortName);

                        bool notEmpty = (value.TitleString().Length > 0);
                        if (notEmpty) {
                            string valueStr = value.TitleString();
                            xmlValueElement.Add(new XText(valueStr));
                        }
                        else {
                            NofMetaModel.SetIsEmptyAttribute(xmlValueElement, true);
                        }
                    }
                    catch (Exception) {
                        Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": getField() threw exception - skipping XML generation");
                    }

                    // XSD
                    xsdFieldElement = Schema.CreateXsElementForNofValue(xsElement, xmlValueElement);
                }
                else if (oneToOneAssociation != null) {
                    Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is IOneToOneAssociation");

                    XElement xmlReferenceElement = xmlFieldElement; // more meaningful locally scoped name

                    try {
                        INakedObjectAdapter referencedNakedObjectAdapter = oneToOneAssociation.GetNakedObject(nakedObjectAdapter);
                        string fullyQualifiedClassName = field.ReturnSpec.FullName;

                        // XML
                        NofMetaModel.SetAttributesForReference(xmlReferenceElement, Schema.Prefix, fullyQualifiedClassName);

                        if (referencedNakedObjectAdapter != null) {
                            NofMetaModel.AppendNofTitle(xmlReferenceElement, referencedNakedObjectAdapter.TitleString());
                        }
                        else {
                            NofMetaModel.SetIsEmptyAttribute(xmlReferenceElement, true);
                        }
                    }
                    catch (Exception) {
                        Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": getAssociation() threw exception - skipping XML generation");
                    }

                    // XSD
                    xsdFieldElement = Schema.CreateXsElementForNofReference(xsElement, xmlReferenceElement, oneToOneAssociation.ReturnSpec.FullName);
                }
                else if (oneToManyAssociation != null) {
                    Log.Debug("objectToElement(NO): " + DoLog("field", fieldName) + " is IOneToManyAssociation");

                    XElement xmlCollectionElement = xmlFieldElement; // more meaningful locally scoped name

                    try {
                        INakedObjectAdapter collection = oneToManyAssociation.GetNakedObject(nakedObjectAdapter);
                        ITypeOfFacet facet = collection.GetTypeOfFacetFromSpec();

                        IObjectSpecImmutable referencedTypeNos = facet.GetValueSpec(collection, metamodelManager.Metamodel);
                        string fullyQualifiedClassName = referencedTypeNos.FullName;

                        // XML
                        NofMetaModel.SetNofCollection(xmlCollectionElement, Schema.Prefix, fullyQualifiedClassName, collection, nakedObjectManager);
                    }
                    catch (Exception) {
                        Log.Warn("objectToElement(NO): " + DoLog("field", fieldName) + ": get(obj) threw exception - skipping XML generation");
                    }

                    // XSD
                    xsdFieldElement = Schema.CreateXsElementForNofCollection(xsElement, xmlCollectionElement, oneToManyAssociation.ReturnSpec.FullName);
                }
                else {
                    Log.Info("objectToElement(NO): " + DoLog("field", fieldName) + " is unknown type; ignored");
                    continue;
                }

                if (xsdFieldElement != null) {
                    xmlFieldElement.AddAnnotation(xsdFieldElement);
                }

                // XML
                Log.Debug("objectToElement(NO): invoking mergeTree for field");
                MergeTree(element, xmlFieldElement);

                // XSD
                if (xsdFieldElement != null) {
                    Log.Debug("objectToElement(NO): adding XS element for field to schema");
                    Schema.AddFieldXsElement(xsElement, xsdFieldElement);
                }
            }

            return place;
        }
コード例 #6
0
 private static string DoLog(string label, INakedObjectAdapter nakedObjectAdapter) {
     return DoLog(label, (nakedObjectAdapter == null ? "(null)" : nakedObjectAdapter.TitleString() + "[" + OidOrHashCode(nakedObjectAdapter) + "]"));
 }
コード例 #7
0
 private void Validate(INakedObjectAdapter adapter)
 {
     if (adapter.Spec.ContainsFacet <IValidateProgrammaticUpdatesFacet>())
     {
         string state = adapter.ValidToPersist();
         if (state != null)
         {
             throw new PersistFailedException(Log.LogAndReturn(string.Format(Resources.NakedObjects.PersistStateError, adapter.Spec.ShortName, adapter.TitleString(), state)));
         }
     }
 }
コード例 #8
0
 public static void CheckCanAssociate(this IResolveStateMachine stateMachine, INakedObjectAdapter associate)
 {
     if (stateMachine.IsPersistent() && associate != null && associate.ResolveState.IsTransient())
     {
         throw new TransientReferenceException(string.Format(Resources.NakedObjects.TransientErrorMessage, associate.TitleString()));
     }
 }
コード例 #9
0
        public Place ObjectToElement(INakedObjectAdapter nakedObjectAdapter)
        {
            var nos = (IObjectSpec)nakedObjectAdapter.Spec;

            var element = Schema.CreateElement(XmlDocument, nos.ShortName, nos.FullName, nos.SingularName, nos.PluralName);

            NofMetaModel.AppendNofTitle(element, nakedObjectAdapter.TitleString());

            var xsElement = Schema.CreateXsElementForNofClass(XsdDocument, element, topLevelElementWritten);

            // hack: every element in the XSD schema apart from first needs minimum cardinality setting.
            topLevelElementWritten = true;

            var place = new Place(nakedObjectAdapter, element);

            NofMetaModel.SetAttributesForClass(element, OidOrHashCode(nakedObjectAdapter));

            var fields = nos.Properties;

            var seenFields = new List <string>();

            foreach (var field in fields)
            {
                var fieldName = field.Id;

                // Skip field if we have seen the name already
                // This is a workaround for getLastActivity(). This method exists
                // in AbstractNakedObject, but is not (at some level) being picked up
                // by the dot-net reflector as a property. On the other hand it does
                // exist as a field in the meta model (NakedObjectSpecification).
                //
                // Now, to re-expose the LastActivity field for .Net, a deriveLastActivity()
                // has been added to BusinessObject. This caused another field of the
                // same name, ultimately breaking the XSD.

                if (seenFields.Contains(fieldName))
                {
                    continue;
                }

                seenFields.Add(fieldName);

                XNamespace ns = Schema.GetUri();

                var xmlFieldElement = new XElement(ns + fieldName);

                XElement xsdFieldElement;
                var      oneToOneAssociation  = field as IOneToOneAssociationSpec;
                var      oneToManyAssociation = field as IOneToManyAssociationSpec;

                if (field.ReturnSpec.IsParseable && oneToOneAssociation != null)
                {
                    var fieldNos = field.ReturnSpec;
                    // skip fields of type XmlValue
                    if (fieldNos?.FullName != null && fieldNos.FullName.EndsWith("XmlValue"))
                    {
                        continue;
                    }

                    var xmlValueElement = xmlFieldElement; // more meaningful locally scoped name

                    try {
                        var value = oneToOneAssociation.GetNakedObject(nakedObjectAdapter);

                        // a null value would be a programming error, but we protect
                        // against it anyway
                        if (value == null)
                        {
                            continue;
                        }

                        var valueNos = value.Spec;

                        // XML
                        NofMetaModel.SetAttributesForValue(xmlValueElement, valueNos.ShortName);

                        var notEmpty = value.TitleString().Length > 0;
                        if (notEmpty)
                        {
                            var valueStr = value.TitleString();
                            xmlValueElement.Add(new XText(valueStr));
                        }
                        else
                        {
                            NofMetaModel.SetIsEmptyAttribute(xmlValueElement, true);
                        }
                    }
                    catch (Exception) {
                        logger.LogWarning($"objectToElement(NO): {DoLog("field", fieldName)}: getField() threw exception - skipping XML generation");
                    }

                    // XSD
                    xsdFieldElement = Schema.CreateXsElementForNofValue(xsElement, xmlValueElement);
                }
                else if (oneToOneAssociation != null)
                {
                    var xmlReferenceElement = xmlFieldElement; // more meaningful locally scoped name

                    try {
                        var referencedNakedObjectAdapter = oneToOneAssociation.GetNakedObject(nakedObjectAdapter);
                        var fullyQualifiedClassName      = field.ReturnSpec.FullName;

                        // XML
                        NofMetaModel.SetAttributesForReference(xmlReferenceElement, Schema.Prefix, fullyQualifiedClassName);

                        if (referencedNakedObjectAdapter != null)
                        {
                            NofMetaModel.AppendNofTitle(xmlReferenceElement, referencedNakedObjectAdapter.TitleString());
                        }
                        else
                        {
                            NofMetaModel.SetIsEmptyAttribute(xmlReferenceElement, true);
                        }
                    }
                    catch (Exception) {
                        logger.LogWarning($"objectToElement(NO): {DoLog("field", fieldName)}: getAssociation() threw exception - skipping XML generation");
                    }

                    // XSD
                    xsdFieldElement = Schema.CreateXsElementForNofReference(xsElement, xmlReferenceElement, oneToOneAssociation.ReturnSpec.FullName);
                }
                else if (oneToManyAssociation != null)
                {
                    var xmlCollectionElement = xmlFieldElement; // more meaningful locally scoped name

                    try {
                        var collection = oneToManyAssociation.GetNakedObject(nakedObjectAdapter);
                        var facet      = collection.GetTypeOfFacetFromSpec();

                        var referencedTypeNos       = facet.GetValueSpec(collection, metamodelManager.Metamodel);
                        var fullyQualifiedClassName = referencedTypeNos.FullName;

                        // XML
                        NofMetaModel.SetNofCollection(xmlCollectionElement, Schema.Prefix, fullyQualifiedClassName, collection, nakedObjectManager);
                    }
                    catch (Exception) {
                        logger.LogWarning($"objectToElement(NO): {DoLog("field", fieldName)}: get(obj) threw exception - skipping XML generation");
                    }

                    // XSD
                    xsdFieldElement = Schema.CreateXsElementForNofCollection(xsElement, xmlCollectionElement, oneToManyAssociation.ReturnSpec.FullName);
                }
                else
                {
                    continue;
                }

                if (xsdFieldElement != null)
                {
                    xmlFieldElement.AddAnnotation(xsdFieldElement);
                }

                // XML
                MergeTree(element, xmlFieldElement);

                // XSD
                if (xsdFieldElement != null)
                {
                    Schema.AddFieldXsElement(xsElement, xsdFieldElement);
                }
            }

            return(place);
        }
コード例 #10
0
 public DataUpdateException(INakedObjectAdapter nakedObjectAdapter, IVersion updated)
     : this(string.Format(Resources.NakedObjects.DataUpdateMessage, nakedObjectAdapter.Version.User, nakedObjectAdapter.TitleString(), DateTime.Now.ToLongTimeString(), Environment.NewLine, Environment.NewLine, nakedObjectAdapter.Version, updated), nakedObjectAdapter.Oid)
 {
 }
コード例 #11
0
 public static void CheckCanAssociate(this IResolveStateMachine stateMachine, INakedObjectAdapter associate) {
     if (stateMachine.IsPersistent() && associate != null && associate.ResolveState.IsTransient()) {
         throw new TransientReferenceException(string.Format(Resources.NakedObjects.TransientErrorMessage, associate.TitleString()));
     }
 }
コード例 #12
0
 private static string DoLog(string label, INakedObjectAdapter nakedObjectAdapter)
 {
     return(DoLog(label, (nakedObjectAdapter == null ? "(null)" : nakedObjectAdapter.TitleString() + "[" + OidOrHashCode(nakedObjectAdapter) + "]")));
 }
コード例 #13
0
 public DataUpdateException(INakedObjectAdapter nakedObjectAdapter, IVersion updated)
     : this(string.Format(Resources.NakedObjects.DataUpdateMessage, nakedObjectAdapter.Version.User, nakedObjectAdapter.TitleString(), DateTime.Now.ToLongTimeString(), Environment.NewLine, Environment.NewLine, nakedObjectAdapter.Version, updated), nakedObjectAdapter.Oid) {}
コード例 #14
0
        public string GetServiceLabel(IObjectFacade objectFacade)
        {
            INakedObjectAdapter nakedObject = objectFacade.WrappedAdapter();

            return(nakedObject.TitleString());
        }