Example usage for java.io ObjectInput getClass

List of usage examples for java.io ObjectInput getClass

Introduction

In this page you can find the example usage for java.io ObjectInput getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.kepler.objectmanager.cache.ActorCacheObject.java

/**
 * deserialize this class//  w  w w  . j  a va 2  s.  c om
 * 
 *@param in
 *            Description of the Parameter
 *@exception IOException
 *                Description of the Exception
 *@exception ClassNotFoundException
 *                Description of the Exception
 */
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    if (isDebugging)
        log.debug("readExternal(" + in.getClass().getName() + ")");

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    byte[] b = new byte[1024];
    int numread = in.read(b, 0, 1024);
    while (numread != -1) {
        bos.write(b, 0, numread);
        numread = in.read(b, 0, 1024);
    }
    bos.flush();
    _actorString = bos.toString();
    try {
        StringReader strR = new StringReader(_actorString);
        InputSource xmlIn = new InputSource(strR);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setEntityResolver(new EntityResolver() {
            public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException {
                if (MOML_PUBLIC_ID_1.equals(publicId)) {
                    return new InputSource(MoMLParser.class.getResourceAsStream("MoML_1.dtd"));
                } else {
                    return null;
                }
            }
        });
        Document doc = builder.parse(xmlIn);
        Node rootNode = doc.getDocumentElement();
        _rootname = rootNode.getNodeName();
        NamedNodeMap nnm = rootNode.getAttributes();
        Node namenode = nnm.getNamedItem("name");
        String nameStr = namenode.getNodeValue();
        this._name = nameStr;
        NodeList probNodes = rootNode.getChildNodes();
        for (int i = 0; i < probNodes.getLength(); i++) {
            Node child = probNodes.item(i);
            if (child.hasAttributes()) {
                NamedNodeMap childAttrs = child.getAttributes();
                Node idNode = childAttrs.getNamedItem("name");
                if (idNode != null) {
                    String nameval = idNode.getNodeValue();
                    if (nameval.equals(NamedObjId.NAME)) {
                        Node idNode1 = childAttrs.getNamedItem("value");
                        String idval = idNode1.getNodeValue();
                        this._lsid = new KeplerLSID(idval);
                    }
                    if (nameval.equals("class")) {
                        Node idNode3 = childAttrs.getNamedItem("value");
                        String classname = idNode3.getNodeValue();
                        this._className = classname;
                    }
                    if (nameval.startsWith("semanticType")) {
                        Node idNode2 = childAttrs.getNamedItem("value");
                        String semtype = idNode2.getNodeValue();
                        _semanticTypes.add(semtype);
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Error in ActorCacheObject(ReadExternal): " + e.getMessage());
    }
}