001: /*
002: * $RCSfile: SceneGraphStreamReader.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.6 $
041: * $Date: 2007/03/21 18:02:25 $
042: * $State: Exp $
043: */
044:
045: package com.sun.j3d.utils.scenegraph.io;
046:
047: import java.io.InputStream;
048: import java.io.DataInputStream;
049: import java.io.IOException;
050: import java.util.HashMap;
051:
052: import javax.media.j3d.BranchGroup;
053: import javax.media.j3d.SceneGraphObject;
054: import javax.media.j3d.Canvas3D;
055: import com.sun.j3d.utils.scenegraph.io.retained.StreamControl;
056: import com.sun.j3d.utils.universe.ConfiguredUniverse;
057:
058: /**
059: * Read and create a (set) of Java3D BranchGraphs or Universe from a Java Stream.
060: */
061: public class SceneGraphStreamReader extends java.lang.Object {
062:
063: private StreamControl control;
064: private DataInputStream in;
065:
066: /** Creates new SceneGraphStreamReader and reads the file header information */
067: public SceneGraphStreamReader(InputStream stream)
068: throws IOException {
069: in = new DataInputStream(stream);
070: control = new StreamControl(in);
071: control.readStreamHeader();
072: }
073:
074: /**
075: * Read and create the universe. If the BranchGraphs were written then
076: * they will be added to the universe before it is returned.
077: */
078: public ConfiguredUniverse readUniverse() throws IOException {
079: return control.readUniverse(in, true, null);
080: }
081:
082: /**
083: * Read and create the universe. If the BranchGraphs were written then
084: * they will be added to the universe before it is returned.
085: * @param canvas The Canvas3D to associate with the universe.
086: */
087: public ConfiguredUniverse readUniverse(Canvas3D canvas)
088: throws IOException {
089: return control.readUniverse(in, true, canvas);
090: }
091:
092: /**
093: * Read and return the graph from the stream.
094: * <code>namedObjects</code> map will be updated with any objects that
095: * were named during the write process
096: */
097: public BranchGroup readBranchGraph(HashMap namedObjects)
098: throws IOException {
099: return control.readBranchGraph(namedObjects);
100: }
101:
102: /**
103: * Set the ClassLoader used to load the scene graph objects and
104: * deserialize user data
105: */
106: public void setClassLoader(ClassLoader classLoader) {
107: control.setClassLoader(classLoader);
108: }
109:
110: /**
111: * Get the ClassLoader used to load the scene graph objects and
112: * deserialize user data
113: */
114: public ClassLoader getClassLoader() {
115: return control.getClassLoader();
116: }
117:
118: /**
119: * Close the SceneGraphStreamReader stream
120: *
121: * @since Java 3D 1.5.1
122: */
123: public void close() throws IOException {
124: in.close();
125: control.close();
126: }
127:
128: }
|