private static Tuple <ActionContext, NakedObjectSpecification> GetActionTypeInternal(string typeName, string actionName)
        {
            if (string.IsNullOrEmpty(typeName.Trim()) || string.IsNullOrWhiteSpace(actionName.Trim()))
            {
                throw new BadRequestNOSException();
            }

            NakedObjectSpecification spec = [email protected]().loadSpecification(typeName);

            if (spec is NoMemberSpecification)
            {
                throw new TypeResourceNotFoundNOSException(typeName);
            }

            ActionWrapper action = spec.GetActionLeafNodes().SingleOrDefault(p => p.getId() == actionName);

            if (action == null)
            {
                throw new ActionResourceNotFoundNOSException(actionName);
            }

            var actionContext = new ActionContext {
                Action = action
            };

            return(new Tuple <ActionContext, NakedObjectSpecification>(actionContext, spec));
        }
        private Tuple <ActionWrapper, NakedObjectSpecification, NakedObjectActionParameter> GetActionParameterTypeInternal(string typeName, string actionName, string parmName)
        {
            if (string.IsNullOrEmpty(typeName.Trim()) || string.IsNullOrWhiteSpace(actionName.Trim()) || string.IsNullOrWhiteSpace(parmName.Trim()))
            {
                throw new BadRequestNOSException();
            }

            NakedObjectSpecification spec = [email protected]().loadSpecification(typeName);

            if (spec is NoMemberSpecification)
            {
                throw new TypeResourceNotFoundNOSException(typeName);
            }

            ActionWrapper action = spec.GetActionLeafNodes().SingleOrDefault(p => p.getId() == actionName);

            if (action == null)
            {
                throw new ActionResourceNotFoundNOSException(actionName);
            }

            NakedObjectActionParameter parm = action.GetParameters().SingleOrDefault(p => p.getId() == parmName);

            if (parm == null)
            {
                throw new ActionResourceNotFoundNOSException(parmName);
            }

            return(new Tuple <ActionWrapper, NakedObjectSpecification, NakedObjectActionParameter>(action, spec, parm));
        }
Example #3
0
        public ITypeFacade GetSpecificationByLinkDomainType(string linkDomainType)
        {
            Type type = GetType(linkDomainType);
            NakedObjectSpecification spec = [email protected]().loadSpecification(type.FullName);

            return(new TypeFacade(spec, null, FrameworkFacade));
        }
 public NakedObjectActionParameter(string id, int number, NakedObjectSpecification spec, ActionWrapper action, object[] choices, object dflt) {
     this.id = id;
     this.number = number;
     this.spec = spec;
     this.action = action;
     this.choices = choices;
     this.dflt = dflt;
 }
        public static ActionWrapper[] GetObjectActions(this NakedObjectSpecification spec)
        {
            MethodInfo getObjectActions = typeof(NakedObjectSpecification).GetMethod("getObjectActions");
            FieldInfo  t      = typeof(Action).GetField("USER");
            object     o      = t.GetValue(null);
            var        result = (object[])getObjectActions.Invoke(spec, new[] { o });

            return(result.Select(r => new ActionWrapper(r)).ToArray());
        }
Example #6
0
 public NakedObjectActionParameter(string id, int number, NakedObjectSpecification spec, ActionWrapper action, object[] choices, object dflt)
 {
     this.id      = id;
     this.number  = number;
     this.spec    = spec;
     this.action  = action;
     this.choices = choices;
     this.dflt    = dflt;
 }
        private Consent IsOfCorrectType(OneToManyAssociation property, PropertyContext context)
        {
            var collectionNakedObject            = (InternalCollectionAdapter)property.get(context.Target);
            NakedObjectSpecification elementSpec = collectionNakedObject.getElementSpecification();

            if (context.ProposedNakedObject.getSpecification().isOfType(elementSpec))
            {
                return(new Allow());
            }
            return(new Veto(string.Format("Not a suitable type; must be a {0}", elementSpec.getFullName())));
        }
        private static Naked GetValue(NakedObjectSpecification specification, object rawValue)
        {
            if (specification.isValue())
            {
                NakedValue value = [email protected]().createValueInstance(specification);
                value.parseTextEntry(rawValue == null ? "" : rawValue.ToString());
                return(value);
            }

            return(rawValue == null ? null : [email protected]().getAdapterForElseCreateAdapterForTransient(rawValue));
        }
 public ITypeFacade GetDomainType(string typeName)
 {
     return(MapErrors(() => {
         NakedObjectSpecification spec = [email protected]().loadSpecification(typeName);
         if (spec is NoMemberSpecification)
         {
             throw new TypeResourceNotFoundNOSException(typeName);
         }
         return new TypeFacade(spec, null, this);
     }));
 }
        private ObjectContextFacade CreateObject(string typeName, ArgumentsContextFacade arguments)
        {
            if (string.IsNullOrWhiteSpace(typeName))
            {
                throw new BadRequestNOSException();
            }

            NakedObject nakedObject;

            try {
                NakedObjectSpecification spec = [email protected]().loadSpecification(typeName);
                nakedObject = [email protected]().createTransientInstance(spec);
            }
            catch (Exception) {
                throw new TypeResourceNotFoundNOSException(typeName);
            }
            return(SetObject(nakedObject, arguments));
        }
        private Tuple <NakedObjectField, NakedObjectSpecification> GetPropertyTypeInternal(string typeName, string propertyName)
        {
            if (string.IsNullOrEmpty(typeName.Trim()) || string.IsNullOrEmpty(propertyName.Trim()))
            {
                throw new BadRequestNOSException();
            }
            NakedObjectSpecification spec = [email protected]().loadSpecification(typeName);

            if (spec is NoMemberSpecification)
            {
                throw new TypeResourceNotFoundNOSException(typeName);
            }

            string nof2Id = propertyName.ToLower();

            NakedObjectField property = spec.getFields().SingleOrDefault(p => p.getId() == nof2Id);

            if (property == null)
            {
                throw new PropertyResourceNotFoundNOSException(propertyName);
            }

            return(new Tuple <NakedObjectField, NakedObjectSpecification>(property, spec));
        }
Example #12
0
        public object GetDomainObjectByOid(IOidTranslation objectId)
        {
            Type type = ValidateObjectId(objectId);

            string[] keys = GetKeys(objectId.InstanceId, type);

            NakedObjectSpecification spec = [email protected]().loadSpecification(type.FullName);

            NakedObject pattern = [email protected]().createTransientInstance(spec);

            PropertyInfo p = pattern.getObject().GetType().GetProperty("Id");

            ((WholeNumber)p.GetValue(pattern.getObject(), null)).setValue(int.Parse(keys.First()));

            var criteria = new TitleCriteria(spec, pattern.titleString(), false);
            TypedNakedCollection results = [email protected]().findInstances(criteria);

            if (results.size() == 0)
            {
                throw new ObjectResourceNotFoundNOSException(objectId.ToString());
            }

            return(results.elementAt(0).getObject());
        }
 private static string GetShortName(NakedObjectSpecification spec)
 {
     return(spec.getFullName().Split('.').Last());
 }
 public static ActionWrapper[] GetActionLeafNodes(this NakedObjectSpecification spec)
 {
     return(spec.GetObjectActions().SelectMany(GetActionLeafNodes).OrderBy(a => a.getId()).ToArray());
 }
Example #15
0
 public TypeFacade(NakedObjectSpecification spec, Naked target, IFrameworkFacade frameworkFacade)
 {
     this.spec       = spec;
     this.target     = target;
     FrameworkFacade = frameworkFacade;
 }
 private static string GetShortName(NakedObjectSpecification spec) {
     return spec.getFullName().Split('.').Last();
 }