/*================================================================================
Copyright (c) 2008 VMware, Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation 
and/or other materials provided with the distribution.

* Neither the name of VMware, Inc. nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior 
written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
================================================================================*/
package com.vmware.vim25.mo;

import java.rmi.RemoteException;

import com.vmware.vim25.DuplicateName;
import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.ProfileCreateSpec;
import com.vmware.vim25.ProfilePolicyMetadata;
import com.vmware.vim25.RuntimeFault;

/**
 * The managed object class corresponding to the one defined in VI SDK API reference.
 * @author Steve JIN (sjin@vmware.com)
 */
public class ProfileManager extends ManagedObject 
{
	public ProfileManager(ServerConnection sc, ManagedObjectReference mor) 
	{
		super(sc, mor);
	}
	
	public Profile[] getProfile()
	{
		return (Profile[]) getCurrentProperty("profile");
	}
	
	public Profile createProfile(ProfileCreateSpec createSpec) throws DuplicateName, RuntimeFault, RemoteException
	{
		ManagedObjectReference profileMor = getVimService().createProfile(getMOR(), createSpec);
		return new Profile(getServerConnection(), profileMor); 
	}
	
	public Profile[] findAssociatedProfile(ManagedEntity entity) throws RuntimeFault, RemoteException
	{
		ManagedObjectReference[] mors = getVimService().findAssociatedProfile(getMOR(), entity.getMOR());
		Profile[] pfs = new Profile[mors.length];
		
		for(int i=0; i<mors.length; i++)
		{
			pfs[i] = new Profile(getServerConnection(), mors[i]);
		}
		return pfs;
	}
	
	public ProfilePolicyMetadata[] queryPolicyMetadata(String[] policyName) throws RuntimeFault, RemoteException
	{
		return getVimService().queryPolicyMetadata(getMOR(), policyName);
	}
	
}

@@ -2291,28 +2291,68 @@
 %7B%0D%0A%09
-%09return (Profil
+  ManagedObjectReference%5B%5D mors = (ManagedObjectReferenc
 e%5B%5D)
- 
 getC
@@ -2375,24 +2375,59 @@
 profile%22);%0D%0A
+%09  return convert2Profiles(mors);%0D%0A
 %09%7D%0D%0A%09%0D%0A%09publ
@@ -2907,171 +2907,37 @@
 %0D%0A%09%09
-Profile%5B%5D pfs = new Profile%5Bmors.length%5D;%0D%0A%09%09%0D%0A%09%09for(int i=0; i%3Cmors.length; i++)%0D%0A%09%09%7B%0D%0A%09%09%09pfs%5Bi%5D = new Profile(getServerConnection(), mors%5Bi%5D);%0D%0A%09%09%7D%0D%0A%09%09return pfs
+return convert2Profiles(mors)
 ;%0D%0A%09
@@ -3133,11 +3133,267 @@
 %0A%09%7D%0D%0A%09%0D%0A
+%09private Profile%5B%5D convert2Profiles(ManagedObjectReference%5B%5D mors)%0D%0A%09%7B%0D%0A    Profile%5B%5D pfs = new Profile%5Bmors.length%5D;%0D%0A  %0D%0A    for(int i=0; i%3Cmors.length; i++)%0D%0A%09  %7B%0D%0A%09    pfs%5Bi%5D = new Profile(getServerConnection(), mors%5Bi%5D);%0D%0A%09  %7D%0D%0A%09  return pfs;%0D%0A%09%7D%0D%0A%09%0D%0A
 %7D%0D%0A

Fix bug: getProfile in HostProfilesManager throws a classcastexceptio https://sourceforge.net/tracker/?func=detail&atid=1073396&aid=3040909&group_id=228007