diff options
Diffstat (limited to 'src/com/sun/apoc/tools/profileeditor/spi/StandalonePolicyManager.java')
-rw-r--r-- | src/com/sun/apoc/tools/profileeditor/spi/StandalonePolicyManager.java | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/src/com/sun/apoc/tools/profileeditor/spi/StandalonePolicyManager.java b/src/com/sun/apoc/tools/profileeditor/spi/StandalonePolicyManager.java new file mode 100644 index 0000000..740a17e --- /dev/null +++ b/src/com/sun/apoc/tools/profileeditor/spi/StandalonePolicyManager.java @@ -0,0 +1,274 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either + * the GNU General Public License Version 2 only ("GPL") or + * the Common Development and Distribution License("CDDL") + * (collectively, the "License"). You may not use this file + * except in compliance with the License. You can obtain a copy + * of the License at www.sun.com/CDDL or at COPYRIGHT. See the + * License for the specific language governing permissions and + * limitations under the License. When distributing the software, + * include this License Header Notice in each file and include + * the License file at /legal/license.txt. If applicable, add the + * following below the License Header, with the fields enclosed + * by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * If you wish your version of this file to be governed by + * only the CDDL or only the GPL Version 2, indicate your + * decision by adding "[Contributor] elects to include this + * software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice + * of license, a recipient has the option to distribute your + * version of this file under either the CDDL, the GPL Version + * 2 or to extend the choice of license to its licensees as + * provided above. However, if you add GPL Version 2 code and + * therefore, elected the GPL Version 2 license, then the + * option applies only if the new code is made subject to such + * option by the copyright holder. + */ + +package com.sun.apoc.tools.profileeditor.spi; + + +import com.sun.apoc.spi.SPIException; +import java.util.HashMap ; +import java.util.Map ; + +import com.sun.apoc.spi.environment.EnvironmentMgr ; +import com.sun.apoc.spi.profiles.Profile; +import com.sun.apoc.spi.profiles.ProfileProvider; + + +/** + * Main access point to the policy management objects, basically maps to an + * instance of the meta-configuration file. + */ +public class StandalonePolicyManager { + + private ProfileProvider mProvider = null; + + + /** + * Constructor from a hashtable providing values for the meta-configuration + * of the policy access (location of entity trees, storage of profiles and + * their assignments). + * + * @param aBootstrapInfo hashtable with bootstrap information + * @throws SPIException if an error occurs. + */ + + public StandalonePolicyManager(ProfileProvider aProvider) throws SPIException { + mProvider = aProvider; + } + + +// public StandalonePolicyManager(Hashtable aBootstrapInfo) throws SPIException { +// mEnvironment = new EnvironmentMgr(aBootstrapInfo) ; +// mEnvironment.checkEnvironment(); +// String [] sources = mEnvironment.getSources() ; +// +// mSources = new PolicySource [sources.length] ; +// for (int i = 0 ; i < sources.length ; ++ i) { +// mSources [i] = new PolicySource(sources [i], mEnvironment) ; +// mSourcesByName.put(sources [i], mSources [i]) ; +// } +// } + + /** + * Returns the entity provider for a given source. + * + * @param aSource source name + * @return entity provider or null if it doesn't exist + */ +// public EntityTreeProvider getEntityProvider(String aSource) { +// PolicySource source = (PolicySource)mSourcesByName.get(aSource) ; +// +// return source != null ? source.getEntityProvider() : null ; +// } + + /** + * Returns the assignment provider for a given source. + * + * @param aSource source name + * @return assignment provider or null if it doesn't exist + */ +// public AssignmentProvider getAssignmentProvider(String aSource) { +// PolicySource source = (PolicySource)mSourcesByName.get(aSource) ; +// +// return source != null ? source.getAssignmentProvider() : null ; +// } + + /** + * Returns the profile provider for a given source. + * + * @param aSource source name + * @return profile provider or null if it doesn't exist + */ + public ProfileProvider getProfileProvider(String aSource) { + + return mProvider != null ? mProvider : null ; + } + +// /** +// * Returns the root entity for a given source. +// * +// * @param aSource source name +// * @return root entity or null if it doesn't exist +// */ +// public Entity getRootEntity(String aSource) throws SPIException { +// PolicySource source = (PolicySource)mSourcesByName.get(aSource) ; +// +// return source != null ? source.getRoot() : null ; +// } + +// /** +// * Returns the entity with given id for a given source. +// * +// * @param aSource source name +// * @param aId entity id +// * @return entity or null if it doesn't exist +// */ +// public Entity getEntity(String aSource, String aId) throws SPIException { +// PolicySource source = (PolicySource)mSourcesByName.get(aSource) ; +// +// return source != null ? source.getEntity(aId) : null ; +// } + +// /** +// * Returns the entity with given id from all sources. +// * +// * @param aId entity id +// * @return entity or null if it doesn't exist +// */ +// public Entity getEntity(String aId) throws SPIException { +// Entity sEntity = null; +// for (int i = 0 ; i < mSources.length && sEntity == null; ++ i) { +// sEntity = getEntity(mSources[i].getName(), aId); +// } +// +// return sEntity ; +// } + + /** + * Returns the profile with given id for a given source. + * + * @param aSource source name + * @param aId profile id + * @return profile or null if it doesn't exist + */ + public Profile getProfile(String aSource, String aId) throws SPIException { + //PolicySource source = (PolicySource)mSourcesByName.get(aSource) ; + //ProfileProvider provider = source.getProfileProvider(); + Profile profile = null; + if (mProvider != null) { + try { + profile = mProvider.getProfile(aId); +// if (profile != null) { +// if (!profile.getApplicability().getStringValue().equals(source.getName())) { +// profile = null; +// } +// } + } catch (SPIException e) { + System.out.println(e); + } + } + + System.out.println("StandPolicyManager: profile = " + profile); + + return profile; + } + + /** + * Returns the profile with given id from all sources. + * + * @param aId profile id + * @return profile or null if it doesn't exist + */ + public Profile getProfile(String aId) throws SPIException { + + Profile sProfile = getProfile("source", aId); + + return sProfile ; + } + + /** + * Returns all the <code>Profile</code>s. + * + * @return an Iterator over all the <code>Profile</code> objects + * @throws <code>SPIException</code> if error occurs + */ +// public Iterator getAllProfiles() throws SPIException { +// ArrayList sProfileList = new ArrayList(); +// for (int i = 0 ; i < mSources.length; ++ i) { +// ProfileProvider sProvider = mSources[i].getProfileProvider(); +// Iterator it = sProvider.getAllProfiles(); +// while (it.hasNext()) { +// Profile sProfile = (Profile)it.next(); +// // if (!sProfileList.contains(sProfile)) { +// sProfileList.add(sProfile); +// // } +// } +// } +// return sProfileList.iterator() ; +// } + + /** + * Returns the profile repository with given id for a given source. + * + * @param aSource source name + * @param aId profile repository id + * @return profile repository or null if it doesn't exist + */ +// public ProfileRepository getProfileRepository(String aSource, String aId) throws SPIException { +// PolicySource source = (PolicySource)mSourcesByName.get(aSource) ; +// ProfileProvider provider = source.getProfileProvider(); +// return provider != null ? provider.getProfileRepository(aId) : null ; +// } + + /** + * Returns the default profile repository for a given source. + * + * @param aSource source name + * @return default profile repository or null if it doesn't exist + */ +// public ProfileRepository getDefaultProfileRepository(String aSource) throws SPIException { +// PolicySource source = (PolicySource)mSourcesByName.get(aSource) ; +// ProfileProvider provider = source.getProfileProvider(); +// return provider != null ? provider.getDefaultProfileRepository() : null ; +// } + + /** + * Returns a copy of the environment table used to establish this object. + * + * @return <code>Hashtable</code> containing environmental settings + */ +// public Hashtable getEnvironment() throws SPIException { +// return mEnvironment.getEnvironment(); +// } + + /** + * Returns the array of policy source names used by this policy manager instance. + * + * @return <code>Hashtable</code> containing environmental settings + */ +// public String[] getSources() throws SPIException { +// return mEnvironment.getSources(); +// } + + /** + * Closes the sessions on the different providers + * + * @throws <code>SPIException</code> if error occurs + */ +// public void close() throws SPIException { +// for (int i = 0 ; i < mSources.length ; ++ i) { +// mSources[i].close(); +// } +// } +} |