001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)RegistryBuilder.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: /**
030: * RegistryBuilder.java
031: *
032: * SUN PROPRIETARY/CONFIDENTIAL.
033: * This software is the proprietary information of Sun Microsystems, Inc.
034: * Use is subject to license terms.
035: *
036: * Created on July 21, 2005, 5:14 PM
037: */package com.sun.jbi.management.registry;
038:
039: import java.io.File;
040:
041: /**
042: *
043: * @author Sun Microsystems, Inc.
044: */
045: public class RegistryBuilder {
046: /**
047: * cache for various registries
048: */
049: private static java.util.HashMap<String, Registry> sRegistryCache;
050:
051: static {
052: initCache();
053: }
054:
055: /**
056: * Creates a new instance of Registry based on the Registry Specification.
057: *
058: * @param spec a Registry specification.
059: * @throws UnsupportedRegistryTypeException when asked to create a Registry
060: * of an unknown type.
061: * @return a specific Registry Implementation based on the RegistrySpec.
062: * @throws RegistryException if problems are encountered in building registry.
063: */
064: public static Registry buildRegistry(RegistrySpec spec)
065: throws UnsupportedRegistryTypeException, RegistryException {
066: String regFolder = spec.getProperties().getProperty(
067: Registry.REGISTRY_FOLDER_PROPERTY);
068:
069: Registry registry = null;
070:
071: if (spec.getType().equals(RegistryType.XML)) {
072: synchronized (sRegistryCache) {
073: if (!sRegistryCache.containsKey(regFolder)) {
074: registry = new com.sun.jbi.management.registry.xml.RegistryImpl(
075: spec);
076:
077: //spec.getManagementContext().setRegistry(registry);
078:
079: sRegistryCache.put(regFolder, registry);
080: } else {
081:
082: registry = sRegistryCache.get(regFolder);
083: }
084: return registry;
085: }
086: } else {
087: throw new UnsupportedRegistryTypeException(spec.getType()
088: .toString());
089: }
090: }
091:
092: /**
093: * Destroy all the Registry Instances
094: */
095: public static void destroyRegistry() {
096: synchronized (sRegistryCache) {
097: java.util.Set<String> folderList = sRegistryCache.keySet();
098:
099: for (String folder : folderList) {
100: Registry registry = sRegistryCache.get(folder);
101: registry.destroy();
102: registry = null;
103: sRegistryCache.remove(folder);
104: }
105: }
106: }
107:
108: /**
109: * Destroy a particular Registry Instance.
110: */
111: public static void destroyRegistry(String folder) {
112: synchronized (sRegistryCache) {
113: if (sRegistryCache.containsKey(folder)) {
114: Registry registry = sRegistryCache.get(folder);
115: registry.destroy();
116: registry = null;
117: sRegistryCache.remove(folder);
118: }
119: }
120: }
121:
122: /**
123: * Return the instance of the registry in the specified folder if one has been
124: * initialized, return null otherwise.
125: */
126: public static Registry getRegistryInstance(String folder) {
127: synchronized (sRegistryCache) {
128: if (sRegistryCache.containsKey(folder)) {
129: return sRegistryCache.get(folder);
130: } else {
131: return null;
132: }
133: }
134: }
135:
136: /**
137: * Initialize the registry cache
138: */
139: private static void initCache() {
140: synchronized (RegistryBuilder.class) {
141: sRegistryCache = new java.util.HashMap();
142: }
143: }
144: }
|