/// <summary> /// This is used to remove the method part from the specified map. /// Removal is performed using the name of the method part. If it /// has been scanned and added to the map then it will be removed /// and will not form part of the class schema. /// </summary> /// <param name="part"> /// this is the part to be removed from the map /// </param> /// <param name="map"> /// this is the map to removed the method part from /// </param> public void Remove(MethodPart part, PartMap map) { String name = part.GetName(); if (name != null) { map.Remove(name); } }
/// <summary> /// This is used to determine whether the specified method can be /// inserted into the given <c>PartMap</c>. This ensures /// that only the most specialized method is considered, which /// enables annotated methods to be overridden in subclasses. /// </summary> /// <param name="method"> /// this is the method part that is to be inserted /// </param> /// <param name="map"> /// this is the part map used to contain the method /// </param> public void Process(MethodPart method, PartMap map) { String name = method.GetName(); if (name != null) { map.put(name, method); } }
/// <summary> /// Constructor for the <c>MethodContact</c> object. This is /// used to compose a point of contact that makes use of a get and /// set method on a class. The specified methods will be invoked /// during the serialization process to get and set values. /// </summary> /// <param name="get"> /// this forms the get method for the object /// </param> /// <param name="set"> /// this forms the get method for the object /// </param> public MethodContact(MethodPart get, MethodPart set) { this.label = get.Annotation; this.items = get.Dependents; this.item = get.Dependent; this.get = get.Method; this.type = get.Type; this.name = get.Name; this.set = set; }
/// <summary> /// This is used to validate the object once all the get methods /// have been matched with a set method. This ensures that there /// is not a set method within the object that does not have a /// match, therefore violating the contract of a property. /// </summary> /// <param name="write"> /// this is a get method that has been extracted /// </param> /// <param name="name"> /// this is the Java Bean methods name to be matched /// </param> public void Validate(MethodPart write, String name) { MethodPart match = read.Take(name); Method method = write.getMethod(); if (match == null) { throw new MethodException("No matching get method for %s in %s", method, type); } }
/// <summary> /// This is used to validate the object once all the get methods /// have been matched with a set method. This ensures that there /// is not a set method within the object that does not have a /// match, therefore violating the contract of a property. /// </summary> public void Validate() { for (String name : write) { MethodPart part = write.get(name); if (part != null) { Validate(part, name); } } }
/// <summary> /// This method is used to pair the get methods with a matching set /// method. This pairs methods using the Java Bean method name, the /// names must match exactly, meaning that the case and value of /// the strings must be identical. Also in order for this to succeed /// the types for the methods and the annotation must also match. /// </summary> public void Build() { for (String name : read) { MethodPart part = read.get(name); if (part != null) { Build(part, name); } } }
/// <summary> /// This method is used to pair the get methods with a matching set /// method. This pairs methods using the Java Bean method name, the /// names must match exactly, meaning that the case and value of /// the strings must be identical. Also in order for this to succeed /// the types for the methods and the annotation must also match. /// </summary> /// <param name="read"> /// this is a get method that has been extracted /// </param> /// <param name="name"> /// this is the Java Bean methods name to be matched /// </param> public void Build(MethodPart read, String name) { MethodPart match = write.Take(name); if (match != null) { Build(read, match); } else { Build(read); // read only } }
/// <summary> /// This method is used to pair the get methods with a matching set /// method. This pairs methods using the Java Bean method name, the /// names must match exactly, meaning that the case and value of /// the strings must be identical. Also in order for this to succeed /// the types for the methods and the annotation must also match. /// </summary> /// <param name="read"> /// this is a get method that has been extracted /// </param> /// <param name="write"> /// this is the write method to compare details with /// </param> public void Build(MethodPart read, MethodPart write) { Annotation label = read.GetAnnotation(); String name = read.GetName(); if (!write.GetAnnotation().equals(label)) { throw new MethodException("Annotations do not match for '%s' in %s", name, type); } Class type = read.GetType(); if (type != write.GetType()) { throw new MethodException("Method types do not match for %s in %s", name, type); } add(new MethodContact(read, write)); }
/// <summary> /// This method is used to remove a particular method from the list /// of contacts. If the <c>Transient</c> annotation is used /// by any method then this method must be removed from the schema. /// In particular it is important to remove methods if there are /// defaults applied to the class. /// </summary> /// <param name="method"> /// this is the method that is to be removed /// </param> /// <param name="label"> /// this is the label associated with the method /// </param> public void Remove(Method method, Annotation label) { MethodPart part = factory.GetInstance(method, label); MethodType type = part.GetMethodType(); if (type == MethodType.GET) { Remove(part, read); } if (type == MethodType.IS) { Remove(part, read); } if (type == MethodType.SET) { Remove(part, write); } }
/// <summary> /// This is used to classify the specified method into either a get /// or set method. If the method is neither then an exception is /// thrown to indicate that the XML annotations can only be used /// with methods following the Java Bean naming conventions. Once /// the method is classified is is added to either the read or /// write map so that it can be paired after scanning is complete. /// </summary> /// <param name="method"> /// this is the method that is to be classified /// </param> public void Process(Method method) { MethodPart part = factory.GetInstance(method); MethodType type = part.GetMethodType(); if (type == MethodType.GET) { Process(part, read); } if (type == MethodType.IS) { Process(part, read); } if (type == MethodType.SET) { Process(part, write); } }
/// <summary> /// This method is used to create a read only contact. A read only /// contact object is used when there is constructor injection used /// by the class schema. So, read only methods can be used in a /// fully serializable and deserializable object. /// </summary> /// <param name="read"> /// this is the part to add as a read only contact /// </param> public void Build(MethodPart read) { add(new MethodContact(read)); }
/// <summary> /// Constructor for the <c>MethodContact</c> object. This is /// used to compose a point of contact that makes use of a get and /// set method on a class. The specified methods will be invoked /// during the serialization process to get and set values. /// </summary> /// <param name="get"> /// this forms the get method for the object /// </param> public MethodContact(MethodPart get) { this(get, null); }