Package java.lang.ref

Examples of java.lang.ref.SoftReference


    synchronized final XMLDTDLoader getDTDLoader(String xmlVersion) {
        // return an instance of XML11DTDProcessor
        if ("1.1".equals(xmlVersion)) {
            while (freeXML11DTDLoaderIndex >= 0) {
                // return first available DTD loader
                SoftReference ref = xml11DTDLoaders[freeXML11DTDLoaderIndex];
                XMLDTDLoaderHolder holder = (XMLDTDLoaderHolder) ref.get();
                if (holder != null && holder.loader != null) {
                    XMLDTDLoader val = holder.loader;
                    holder.loader = null;
                    --freeXML11DTDLoaderIndex;
                    return val;
                }
                xml11DTDLoaders[freeXML11DTDLoaderIndex--] = null;
            }
            //MF
            return (XMLDTDLoader) (ObjectFactory
                    .newInstance(
                        "mf.org.apache.xerces.impl.dtd.XML11DTDProcessor",
                        ObjectFactory.findClassLoader(),
                        true));
        }
        // return an instance of XMLDTDLoader
        else {
            while (freeXML10DTDLoaderIndex >= 0) {
                // return first available DTD loader
                SoftReference ref = xml10DTDLoaders[freeXML10DTDLoaderIndex];
                XMLDTDLoaderHolder holder = (XMLDTDLoaderHolder) ref.get();
                if (holder != null && holder.loader != null) {
                    XMLDTDLoader val = holder.loader;
                    holder.loader = null;
                    --freeXML10DTDLoaderIndex;
                    return val;
View Full Code Here


                xml11DTDLoaderCurrentSize += SIZE;
                SoftReference [] newarray = new SoftReference[xml11DTDLoaderCurrentSize];
                System.arraycopy(xml11DTDLoaders, 0, newarray, 0, xml11DTDLoaders.length);
                xml11DTDLoaders = newarray;
            }
            SoftReference ref = xml11DTDLoaders[freeXML11DTDLoaderIndex];
            if (ref != null) {
                XMLDTDLoaderHolder holder = (XMLDTDLoaderHolder) ref.get();
                if (holder != null) {
                    holder.loader = loader;
                    return;
                }
            }
            xml11DTDLoaders[freeXML11DTDLoaderIndex] = new SoftReference(new XMLDTDLoaderHolder(loader));
        }
        // release an instance of XMLDTDLoader
        else {
            ++freeXML10DTDLoaderIndex;
            if (xml10DTDLoaders.length == freeXML10DTDLoaderIndex) {
                // resize size of the DTD loaders
                xml10DTDLoaderCurrentSize += SIZE;
                SoftReference [] newarray = new SoftReference[xml10DTDLoaderCurrentSize];
                System.arraycopy(xml10DTDLoaders, 0, newarray, 0, xml10DTDLoaders.length);
                xml10DTDLoaders = newarray;
            }
            SoftReference ref = xml10DTDLoaders[freeXML10DTDLoaderIndex];
            if (ref != null) {
                XMLDTDLoaderHolder holder = (XMLDTDLoaderHolder) ref.get();
                if (holder != null) {
                    holder.loader = loader;
                    return;
                }
            }
            xml10DTDLoaders[freeXML10DTDLoaderIndex] = new SoftReference(new XMLDTDLoaderHolder(loader));
        }
    }
View Full Code Here

                (srcURLs[idx].toString());

            GraphicsNode gn;
            gn = createSVGImageNode(ctx, multiImgElem,
                                    bounds, svgDoc);
            srcs[idx] = new SoftReference(gn);
            return gn;
        } catch (Exception ex) { /* ex.printStackTrace(); */ }

        try {
            GraphicsNode gn;
            gn = createRasterImageNode(ctx, multiImgElem,
                                       bounds, srcURLs[idx]);
            srcs[idx] = new SoftReference(gn);
            return gn;
        } catch (Exception ex) { /* ex.printStackTrace(); */ }

        return null;
    }
View Full Code Here

        _factory = factory;
        if(null != _factory) {
            for(int i=0;i<initSize;i++) {
                Object obj = _factory.makeObject();
                _factory.passivateObject(obj);
                _pool.add(new SoftReference(obj));
            }
        }
    }
View Full Code Here

                    throw new NoSuchElementException();
                } else {
                    obj = _factory.makeObject();
                }
            } else {
                SoftReference ref = (SoftReference)(_pool.remove(_pool.size() - 1));
                obj = ref.get();
            }
        }
        if(null != _factory && null != obj) {
            _factory.activateObject(obj);
        }
View Full Code Here

        boolean shouldDestroy = !success;
        synchronized(this) {
            _numActive--;
            if(success) {
                _pool.add(new SoftReference(obj));
            }
            notifyAll(); // _numActive has changed
        }

        if(shouldDestroy) {
View Full Code Here

     * Creates a new PDF reference.
     * @param obj the object to be referenced
     */
    public PDFReference(PDFObject obj) {
        this.indirectReference = obj.referencePDF();
        this.objReference = new SoftReference(obj);
    }
View Full Code Here

            // Not being very smart about this at the moment.  One could, for example,
            // see that the schemaLocation or baseUri is the same as another, but differs
            // only by a trailing slash.  As it is now, we assume a single character difference
            // means it's a schema that has yet to be resolved.
            schemaKey = Thread.currentThread().getId() + targetNamespace + schemaLocation + baseUri;
            SoftReference softref = (SoftReference)resolvedSchemas.get(schemaKey);
            if (softref != null) {
                XmlSchema resolvedSchema = (XmlSchema)softref.get();
                if (resolvedSchema != null) {
                    return resolvedSchema;
                }
            }
        }
       
    //use the entity resolver provided if the schema location is present null
    if (schemaLocation != null && !"".equals(schemaLocation)) {
      InputSource source = collection.getSchemaResolver().resolveEntity(
          targetNamespace, schemaLocation, baseUri);

      //the entity resolver was unable to resolve this!!
      if (source == null) {
        //try resolving it with the target namespace only with the
        //known namespace map
        XmlSchema schema = collection.getKnownSchema(targetNamespace);
        if (schema != null) {
          return schema;
        }else{
          return null;
        }
      }
      final String systemId = source.getSystemId() == null ? schemaLocation
          : source.getSystemId();
      // Push repaired system id back into source where read sees it.
      // It is perhaps a bad thing to patch the source, but this fixes
      // a problem.
      source.setSystemId(systemId);
      final SchemaKey key = new XmlSchemaCollection.SchemaKey(
          targetNamespace, systemId);
      XmlSchema schema = collection.getSchema(key);
      if (schema != null) {
        return schema;
      }
      if (collection.check(key)) {
        collection.push(key);
        try {
                    XmlSchema readSchema = collection.read(source, null, validator);
                    if (resolvedSchemas != null) {
                        resolvedSchemas.put(schemaKey, new SoftReference(readSchema));
                    }
          return readSchema;
        } catch (Exception e) {
          throw new RuntimeException(e);
        } finally {
View Full Code Here

    /**
     * Returns a thread local QNameCache
     */
    public static QNameCache getQNameCache ( )
    {
        SoftReference softRef = (SoftReference)_threadLocalLoaderQNameCache.get();
        QNameCache qnameCache = (QNameCache) (softRef).get();
        if (qnameCache==null)
        {
            qnameCache = new QNameCache( 32 );
            _threadLocalLoaderQNameCache.set(new SoftReference(qnameCache));
        }
        return qnameCache;
    }
View Full Code Here

            }
        };

    static ScrubBuffer getScrubBuffer(int wsr)
    {
        SoftReference softRef = (SoftReference) tl_scrubBuffer.get();
        ScrubBuffer scrubBuffer = (ScrubBuffer) (softRef).get();
        if (scrubBuffer == null)
        {
            scrubBuffer = new ScrubBuffer();
            tl_scrubBuffer.set(new SoftReference(scrubBuffer));
        }

        scrubBuffer.init(wsr);
        return scrubBuffer;
    }
View Full Code Here

TOP

Related Classes of java.lang.ref.SoftReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.