Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[emf-dev] Loading using streams

Title: Loading using streams

    I was using emf serialization in my client code:

                        java.lang.String data = null;
                        try{
                               
                                // Read in data file and stringify it
                                File inpf = new File("data.xml");
                                FileInputStream fis = new FileInputStream(inpf);
                                byte [] b = new byte[5000];
                                int len = fis.read(b);
                                data = new java.lang.String(b,0,len);
                        }
                        catch(Exception e){}

                        // Create input stream for resource
                        ByteArrayInputStream ins = new ByteArrayInputStream(data.getBytes());

                        // Create resource
                        Resource resource = new XMLResourceImpl();

                        // Create XMLMap, used for proper XML mapping. This is an empty Map,
                        // it is using generated annotations for proper streaming
                        XMLResource.XMLMap xmlMap = new XMLMapImpl();

                        // Create options map for loading
                        Map options = new HashMap();

                        // Populate options
                        options.put(XMLResource.OPTION_XML_MAP,xmlMap);

                        // Initialize package, required for putting package in the registry
                        CnaPackage cPackage = CnaPackageImpl.init();
                        try{
                                resource.load(ins,options);
                        }
                        catch(Exception e){
                                e.printStackTrace();
                        }

                        // Get the root element from the resource
                        Message message = (Message)(resource.getContents().get(0));

        This seems to be fairly straightforward code, but it does not work, because I am not using resource, thus not defining URL. I have two options. Either to create resource just for the sake of URL or modify XMLHandler, XMLLoadImpl and XMLResourceImpl to check for nulls. Is it a bug? Feature? What is your recommendation?


Back to the top