001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026: package com.sun.j2me.global;
027:
028: import javax.microedition.global.*;
029:
030: /**
031: * This class customizes the MIA resources implementation from the
032: * <code>com.sun.j2me.global</code> package to access device resources through
033: * native function calls. Application resources handling functionality of
034: * {@link com.sun.j2me.global.AppResourceManager} is reused.
035: */
036: public class ResourceAbstractionLayerImpl extends
037: ResourceAbstractionLayer {
038: /**
039: * Maximum cache size.
040: */
041: private final static int MAX_CACHE_SIZE = 250;
042: // kB
043:
044: /**
045: * Maximum cached resource size.
046: */
047: private final static int MAX_RESOURCE_SIZE = 25;
048: // kB
049:
050: /**
051: * Use cached common resources.
052: * This implementation alows to
053: * set limit for maximum cache size in kB
054: * and maximum resource size in kB.
055: */
056: private final static ResourceCache commonResourceCache = new ResourceCacheLRUImpl(
057: MAX_CACHE_SIZE, MAX_RESOURCE_SIZE);
058:
059: /**
060: * Use cached device resources.
061: * This implementation alows to
062: * set limit for maximum cache size in kB
063: * and maximum resource size in kB.
064: */
065: private final static ResourceCache deviceResourceCache = new ResourceCacheLRUImpl(
066: MAX_CACHE_SIZE, MAX_RESOURCE_SIZE);
067:
068: /**
069: * A resource manager factory for creating device resource managers.
070: */
071: private ResourceManagerFactory devResourceManagerFactory;
072:
073: /**
074: * A resource manager factory for creating application resource managers.
075: */
076: private ResourceManagerFactory appResourceManagerFactory;
077:
078: /**
079: * Create instance of <code>ResourceAbstractionLayerImpl</code>. This
080: * constructor is necessary because of <code>Class.forName()</code> creation
081: * call in {@link com.sun.j2me.global.ResourceAbstractionLayer#getInstance}.
082: */
083: public ResourceAbstractionLayerImpl() {
084: }
085:
086: /**
087: * Create device resource manager factory.
088: *
089: * @return instance of <code>DevResourceManagerFactory</code>
090: * with caching enabled
091: */
092: public ResourceManagerFactory getDevResourceManagerFactory() {
093: if (devResourceManagerFactory == null) {
094: devResourceManagerFactory = new DevResourceManagerFactory(
095: deviceResourceCache);
096: }
097: return devResourceManagerFactory;
098: }
099:
100: /**
101: * Create application resource manager factory.
102: *
103: * @return instance of <code>AppResourceManagerFactory</code>
104: * with caching enabled
105: */
106: public ResourceManagerFactory getAppResourceManagerFactory() {
107: if (appResourceManagerFactory == null) {
108: appResourceManagerFactory = new AppResourceManagerFactory(
109: commonResourceCache);
110: }
111: return appResourceManagerFactory;
112: }
113: }
|