You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Glen Daniels <gd...@macromedia.com> on 2001/05/22 16:44:46 UTC
RE: cvs commit: xml-axis/java/src/org/apache/axis/server AxisServ
er.java
This brings up something I've been meaning to comment on for a while.
I'd like to get a sense of how other people feel about the whole idea of
serializing these registries as Java object files. To me, it seems like
this is an unnecessary and potentially broken duplication of data. We've
got this same information in various XML files (deployment/config), and I
would vote to just keep it there instead. That way, there's no possibility
of the XML getting out of sync with the *.reg files, and changes which are
made programmatically to the engine might also be stored in a human-readable
way. This is basically the "DRY" (Don't Repeat Yourself) principle, which
is covered quite well by Andrew Hunt and David Thomas in "The Pragmatic
Programmer".
--Glen
> -----Original Message-----
> From: rubys@apache.org [mailto:rubys@apache.org]
> Sent: Tuesday, May 22, 2001 9:41 AM
> To: xml-axis-cvs@apache.org
> Subject: cvs commit: xml-axis/java/src/org/apache/axis/server
> AxisServer.java
>
>
> rubys 01/05/22 06:41:23
>
> Modified: java/src/org/apache/axis/encoding
> TypeMappingRegistry.java
> java/src/org/apache/axis/server AxisServer.java
> Log:
> Make TypeMappingRegistry self managing (like the other registries)
>
> Revision Changes Path
> 1.10 +57 -25
> xml-axis/java/src/org/apache/axis/encoding/TypeMappingRegistry.java
>
> Index: TypeMappingRegistry.java
> ===================================================================
> RCS file:
> /home/cvs/xml-axis/java/src/org/apache/axis/encoding/TypeMappi
> ngRegistry.java,v
> retrieving revision 1.9
> retrieving revision 1.10
> diff -u -r1.9 -r1.10
> --- TypeMappingRegistry.java 2001/05/21 19:36:18 1.9
> +++ TypeMappingRegistry.java 2001/05/22 13:41:16 1.10
> @@ -72,6 +72,29 @@
> */
> public class TypeMappingRegistry implements Serializer {
>
> + // default location for save/load
> + private String fileName = null;
> +
> + /**
> + * Constructor for persistent registries
> + */
> + public TypeMappingRegistry(String fileName) {
> + this();
> + this.fileName = fileName;
> + }
> +
> + /**
> + * Default constructor (transient registry)
> + */
> + public TypeMappingRegistry() {}
> +
> + /**
> + * Init (ie. load settings...)
> + */
> + public void init() {
> + // load();
> + }
> +
> class SerializerDescriptor implements Serializable {
> QName typeQName;
> Serializer serializer;
> @@ -112,6 +135,7 @@
> Serializer serializer) {
> if (s == null) s = new Hashtable();
> s.put(_class, new SerializerDescriptor(qName, serializer));
> + save();
> }
>
> public void addDeserializerFactory(QName qname,
> @@ -119,6 +143,7 @@
> DeserializerFactory
> deserializerFactory) {
> if (d == null) d= new Hashtable();
> d.put(qname, new DeserializerDescriptor(_class,
> deserializerFactory));
> + save();
> }
>
> public Serializer getSerializer(Class _class) {
> @@ -160,10 +185,12 @@
>
> public void removeSerializer(Class _class) {
> if (s != null) s.remove(_class);
> + save();
> }
>
> public void removeDeserializer(QName qname) {
> if (d != null) d.remove(qname);
> + save();
> }
>
> public boolean hasSerializer(Class _class) {
> @@ -178,33 +205,38 @@
> return false;
> }
>
> - public void save(OutputStream out) throws Exception {
> - Hashtable reg = new Hashtable();
> - reg.put("SERIALIZERS", s);
> - reg.put("DESERIALIZERS", d);
> - ObjectOutputStream oos = new ObjectOutputStream(out);
> - oos.writeObject(reg);
> - oos.close();
> - }
> -
> - public void load(InputStream in) throws Exception {
> - ObjectInputStream ois = new ObjectInputStream(in);
> - Hashtable reg = (Hashtable)ois.readObject();
> - s = (Hashtable)reg.get("SERIALIZERS");
> - d = (Hashtable)reg.get("DESERIALIZERS");
> - ois.close();
> - }
> -
> - public void save(String filename) throws Exception {
> - FileOutputStream fos = new FileOutputStream(filename);
> - save(fos);
> - }
> -
> - public void load(String filename) throws Exception {
> - FileInputStream fis = new FileInputStream(filename);
> - load(fis);
> + public void save() {
> + if (fileName == null) return;
> +
> + try {
> + FileOutputStream out = new FileOutputStream(fileName);
> + Hashtable reg = new Hashtable();
> + if (s!=null) reg.put("SERIALIZERS", s);
> + if (d!=null) reg.put("DESERIALIZERS", d);
> + ObjectOutputStream oos = new ObjectOutputStream(out);
> + oos.writeObject(reg);
> + oos.close();
> + } catch (Exception e) {
> + e.printStackTrace( System.err );
> + }
> }
> +
> + private void load() {
> + if (fileName == null) return;
>
> + try {
> + FileInputStream in = new FileInputStream(fileName);
> + ObjectInputStream ois = new ObjectInputStream(in);
> + Hashtable reg = (Hashtable)ois.readObject();
> + s = (Hashtable)reg.get("SERIALIZERS");
> + d = (Hashtable)reg.get("DESERIALIZERS");
> + ois.close();
> + } catch (FileNotFoundException fnfe) {
> + } catch (Exception e) {
> + e.printStackTrace( System.err );
> + }
> + }
> +
> public Attributes setTypeAttribute(Attributes
> attributes, QName type,
>
> SerializationContext context)
> {
>
>
>
> 1.9 +1 -7
> xml-axis/java/src/org/apache/axis/server/AxisServer.java
>
> Index: AxisServer.java
> ===================================================================
> RCS file:
> /home/cvs/xml-axis/java/src/org/apache/axis/server/AxisServer.java,v
> retrieving revision 1.8
> retrieving revision 1.9
> diff -u -r1.8 -r1.9
> --- AxisServer.java 2001/05/22 05:25:35 1.8
> +++ AxisServer.java 2001/05/22 13:41:20 1.9
> @@ -110,13 +110,7 @@
> addOption( Constants.SERVICE_REGISTRY, sr );
>
> // Load the registry of deployed types
> - TypeMappingRegistry tmr = new TypeMappingRegistry();
> - try {
> - tmr.load("typemap-supp.reg");
> - } catch (Exception e) {
> - // ignore FileNotFoundException
> - // what to do about the rest?
> - }
> + TypeMappingRegistry tmr = new
> TypeMappingRegistry("typemap-supp.reg");
> tmr.setParent(new SOAPTypeMappingRegistry());
> addOption( Constants.TYPEMAP_REGISTRY, tmr );
>
>
>
>
>
RE: cvs commit: xml-axis/java/src/org/apache/axis/server
AxisServer.java
Posted by Rob Jellinghaus <ro...@unrealities.com>.
At 10:44 AM 5/22/2001 -0400, Glen Daniels wrote:
>I'd like to get a sense of how other people feel about the whole idea of
>serializing these registries as Java object files. To me, it seems like
>this is an unnecessary and potentially broken duplication of data.
+1 (do I get to say that yet? :-)
It's also very fragile with respect to recompilation. Right now, for some
reason I don't fully understand, my IDE and build.xml produce incompatible
class files with respect to the .reg files, so I get Java deserialization
exceptions on the .reg files when I go from building in one environment to
the other.
Cheers,
Rob