From: <jam...@di...> - 2012-02-09 13:09:37
|
Hi Matej Just got to this, looks fine for a quick fix. Eliminates the two names given to structureArrays. James > -----Original Message----- > From: Matej Sekoranja [mailto:mat...@co...] > Sent: 24 January 2012 23:38 > To: epi...@li... > Subject: pvData change suggestion > > Hi, > > on the train I have some time to think... here is what I've come up with. > Changes are minor. > > If we simply add a method createStructure(Field[]) that creates so called > "anonymous structure", we can get something that produces the "result" we > want: > > > Scalar xField = fieldCreate.createScalar("x", ScalarType.pvDouble); Scalar > yField = fieldCreate.createScalar("y", ScalarType.pvDouble); // this is a new > method, it creates an anonymous structure Structure pointStructure = > fieldCreate.createStructure(new Field[] { xField, yField } ); > > // note that pointStructure has no name, so we do not have a problem with 2 > names... > StructureArray points = fieldCreate.createStructureArray("points", > pointStructure); > > > Scalar valueField = fieldCreate.createScalar("value", ScalarType.pvInt); > > // in order to add name to a structure you must wrap it with the > StructureMember class Structure topStructure = fieldCreate.createStructure( > new Field[] { > valueField, > points, > new StructureMember("point1", pointStructure), > new StructureMember("point2", pointStructure) > }); > > > --- > > Now, how to "tweak" current code that is still works. > Currently Field interface declares getFieldName(). Structure extends Field. > Note that javaIOC XML parser uses getFieldName() for different reasons that as > a member name. > > Implementation of a new method createStructure(Fields[] fields) becomes: > > public Structure createStructure(Field[] field) { > return new BaseStructure(null,field); } > > We declare StructureMember as: > > final class StructureMember implements Structure { > private final Structure structure; > private final String memberName; > > public StructureMember(String memberName, Structure structure) > { > this.memberName = memberName; > this.structure = structure; > } > > // we implement getFieldName() to return memberName instead of null > // getFieldName() should be called getMemberName(), but its called > getFieldName() due to legacy code > public String getFieldName() > { > return memberName; > } > > public Type getType() > { > return Type.pvStructure; > } > > // for rest of Structure implementation we simply delegate a call to > structure instance. > } > > pvAccess code is changed: Structure/StructureArray serialization, caching, > etc... > > > We deprecate method fieldCreate.createStructure(String fieldName, Field[] > fields) - should not be used, since it does not allow sharing of introspection > instances. However when sent over the wire, sharing will happen. > > getFieldName() is used as "member name". Since scalars, arrays and > structureArrays are never standalone current methods are OK. > The only "problem" are structure. For this we use StructureMember. > Note that we can use getFieldName() for top structure or not. > > Matej > > ps I wrote this pretty fast... so I hope it is understandable. > > ------------------------------------------------------------------------------ > Keep Your Developer Skills Current with LearnDevNow! > The most comprehensive online learning library for Microsoft developers is > just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro > Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-d2d -- This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail. Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message. Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom |