From: Wolfgang T. <ta...@us...> - 2005-08-16 15:32:17
|
Update of /cvsroot/sblim/wbemsmt-dns-bl/java/org/sblim/wbemsmt/dns/bl/fco In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14080/java/org/sblim/wbemsmt/dns/bl/fco Added Files: DNSAddressMatchList.java DNSResourceRecord.java DNSIPAddress.java DNSSetting.java DNSConfiguration.java DNSForwardZone.java DNSMasterZone.java DNSAclForService.java DNSHintZone.java DNSAclForZone.java DNSService.java DNSZone.java DNSSlaveZone.java DNSCommonBase.java Log Message: WBEM-SMT DNS BusinessLogic component. First initial upload. --- NEW FILE: DNSMasterZone.java --- /** * DNSMasterZone.java * * (C) Copyright IBM Corp. 2005 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://www.opensource.org/licenses/cpl1.0.php * * Author: Rodrigo Ceron <rc...@br...> * * Contributors: **/ package org.sblim.wbemsmt.dns.bl.fco; import java.util.ArrayList; import java.util.Enumeration; import java.util.Vector; import org.sblim.wbem.cim.CIMClass; import org.sblim.wbem.cim.CIMDataType; import org.sblim.wbem.cim.CIMException; import org.sblim.wbem.cim.CIMInstance; import org.sblim.wbem.cim.CIMObjectPath; import org.sblim.wbem.cim.CIMProperty; import org.sblim.wbem.cim.CIMValue; import org.sblim.wbem.cim.UnsignedInt16; import org.sblim.wbem.cim.UnsignedInt32; import org.sblim.wbem.client.CIMClient; import org.sblim.wbemsmt.exception.InvalidCimClassException; import org.sblim.wbemsmt.exception.InvalidParameterException; import org.sblim.wbemsmt.exception.InvalidPropertyValueException; import org.sblim.wbemsmt.exception.ObjectCreationException; import org.sblim.wbemsmt.exception.PropertyNotFoundException; public class DNSMasterZone extends DNSZone{ public final static String CIM_CLASS_NAME = "Linux_DnsMasterZone"; public final static String CIM_PROPERTY_CONTACT = "Contact"; public final static String CIM_PROPERTY_SN = "SerialNumber"; public final static String CIM_PROPERTY_REFRESH = "Refresh"; public final static String CIM_PROPERTY_RETRY = "Retry"; public final static String CIM_PROPERTY_EXPIRE = "Expire"; public final static String CIM_PROPERTY_NCTTL = "NegativeCachingTTL"; public final static String CIM_PROPERTY_SERVER = "Server"; public final static String CIM_PROPERTY_FORWARD = "Forward"; public final static String CIM_PROPERTY_FORWARDERS = "Forwarders"; public final static String[] CIM_VALUEMAP_FORWARD = {"Unknown","Only","First"}; public final static short FORWARD_UNKNOWN = 0; public final static short FORWARD_ONLY = 1; public final static short FORWARD_FIRST = 2; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_UPDATE_ACL_FOR_ZONE = "Linux_DnsAllowUpdateACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_QUERY_ACL_FOR_ZONE = "Linux_DnsAllowQueryACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_TRANSFER_ACL_FOR_ZONE = "Linux_DnsAllowTransferACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_NOTIFY_ACL_FOR_ZONE = "Linux_DnsAllowNotifyACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_BLACKHOLE_ACL_FOR_ZONE = "Linux_DnsBlackholeACLForZone"; /**Creates a DNSMasterZone Object from a cim instance * @param cimInstance * @param cimObjectPath * @throws ObjectCreationException * @throws InvalidCimClassException */ public DNSMasterZone(CIMInstance cimInstance, CIMObjectPath cimObjectPath) throws ObjectCreationException, InvalidCimClassException { super(cimInstance,cimObjectPath); this.className = CIM_CLASS_NAME; } /**Creates a new DNSMasterZone instance. This is not reflected into the * cim server yet, call createInstance later * @param cimClient * @throws CIMException */ public DNSMasterZone(CIMClient cimClient) throws CIMException { super(cimClient); this.className = CIM_CLASS_NAME; try{ this.cimObjectPath = new CIMObjectPath(this.className); CIMClass cimClass = cimClient.getClass(this.cimObjectPath, false, true, true); this.cimInstance = cimClass.newInstance(); this.original_cimInstance = (CIMInstance)cimInstance.clone(); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } } /* (non-Javadoc) * @see com.ibm.wbem.smt.dns.DNSZone#enumerateInstanceNames(com.ibm.wbem.smt.CimClient) */ public static ArrayList enumerateInstanceNames(CIMClient cimClient) throws CIMException { ArrayList cimInstanceNamesList = new ArrayList(); Enumeration enum = null; CIMObjectPath cimObjectPath = null; try{ enum = cimClient.enumerateInstanceNames(new CIMObjectPath(CIM_CLASS_NAME)); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } while (enum.hasMoreElements()) { cimObjectPath = (CIMObjectPath) enum.nextElement(); cimInstanceNamesList.add(cimObjectPath); } return cimInstanceNamesList; } /* (non-Javadoc) * @see com.ibm.wbem.smt.dns.DNSZone#enumerateInstances(com.ibm.wbem.smt.CimClient) */ public static ArrayList enumerateInstances(CIMClient cimClient) throws CIMException { ArrayList cimInstanceList = new ArrayList(); Enumeration enum = null; try{ enum = cimClient.enumerateInstances(new CIMObjectPath(CIM_CLASS_NAME)); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } CIMInstance cimInstance = null; while (enum.hasMoreElements()) { cimInstance = (CIMInstance) enum.nextElement(); try { cimInstanceList.add(new DNSMasterZone(cimInstance, cimInstance.getObjectPath())); } catch(ObjectCreationException e) { System.out.println("Null Cim Instance passed!"); } catch(InvalidCimClassException e){ System.out.println("Cim Instance's class must be "+CIM_CLASS_NAME); } } return cimInstanceList; } /* (non-Javadoc) * @see com.ibm.wbem.smt.dns.DNSZone#getInstance(com.ibm.wbem.smt.CimClient, javax.wbem.cim.CIMObjectPath) */ public static DNSZone getInstance(CIMClient cimClient, CIMObjectPath cimObjectPath) throws CIMException, InvalidParameterException { CIMInstance cimInstance = null; DNSMasterZone zone = null; if (cimObjectPath == null) { throw new InvalidParameterException("Null ObjectPath passed!"); } try{ cimInstance = cimClient.getInstance(cimObjectPath); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } try { zone = new DNSMasterZone(cimInstance, cimObjectPath); } catch (ObjectCreationException e) { System.out.println("Returned Cim Instance was null"); return null; } catch (InvalidCimClassException e){ System.out.println("ObjectPath is not a path to " + CIM_CLASS_NAME); return null; } return zone; } public static DNSMasterZone createInstance(CIMClient cimClient, DNSMasterZone dnsMasterZone) throws CIMException, InvalidParameterException { DNSMasterZone masterZone = null; CIMObjectPath cimObjectPath = null; if (dnsMasterZone == null || dnsMasterZone.getCimInstance() == null) { throw new InvalidParameterException("Invalid Zone passed for creation"); } try{ cimObjectPath = cimClient.createInstance(dnsMasterZone.getCimObjectPath(), dnsMasterZone.getCimInstance()); }catch (CIMException e){ System.out.println(e.getMessage()); throw e; } try { masterZone = (DNSMasterZone) getInstance(cimClient,cimObjectPath); } catch(Exception e){ System.out.println("Problem to retrive created master zone!"); } return masterZone; } /**Gets the associated Update ACL names * @param cimClient * @return An ArrayList of ACL ObjectPaths * @throws CIMException */ public ArrayList getAssociatedAllowUpdateACLNames(CIMClient cimClient) throws CIMException { Enumeration enum = null; try{ enum = cimClient.associatorNames(this.cimObjectPath, CIM_ASSOCIATOR_CLASS_ALLOW_UPDATE_ACL_FOR_ZONE, DNSAddressMatchList.CIM_CLASS_NAME, "Element","Setting"); } catch (CIMException e){ System.out.println("Error within cim client"); throw e; } ArrayList aclNamesList = new ArrayList(); while (enum.hasMoreElements()) { aclNamesList.add(enum.nextElement()); } return aclNamesList; } /**Gets the associated Update ACLs * @param cimClient * @return An ArrayList of DNSAddressMatchList objects * @throws CIMException */ public ArrayList getAssociatedAllowUpdateACL(CIMClient cimClient) throws CIMException { Enumeration enum = null; try{ enum = cimClient.associators(this.cimObjectPath, CIM_ASSOCIATOR_CLASS_ALLOW_UPDATE_ACL_FOR_ZONE, DNSAddressMatchList.CIM_CLASS_NAME, "Element","Setting",false,false,null); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } ArrayList aclList = new ArrayList(); while (enum.hasMoreElements()) { CIMInstance dummyInstance = (CIMInstance) enum.nextElement(); try { aclList.add(new DNSAddressMatchList(dummyInstance, dummyInstance.getObjectPath())); } catch (ObjectCreationException e){ System.out.println("Tried to create an ACL from null value"); } catch (InvalidCimClassException e){ System.out.println("Cim Instance is not of type "+DNSAddressMatchList.CIM_CLASS_NAME); } } return aclList; } /**Gets the associated Query ACL names * @param cimClient * @return An ArrayList of ObjectPaths * @throws CIMException */ public ArrayList getAssociatedAllowQueryACLNames(CIMClient cimClient) throws CIMException { Enumeration enum = null; try{ enum = cimClient.associatorNames(this.cimObjectPath, CIM_ASSOCIATOR_CLASS_ALLOW_QUERY_ACL_FOR_ZONE, DNSAddressMatchList.CIM_CLASS_NAME, "Element","Setting"); } catch (CIMException e){ System.out.println(e.getMessage()); throw e; } ArrayList aclNamesList = new ArrayList(); while (enum.hasMoreElements()) { aclNamesList.add(enum.nextElement()); } return aclNamesList; } /**Gets the associated Query ACLs * @param cimClient * @return An ArrayList of DNSAddressMatchList objects * @throws CIMException */ public ArrayList getAssociatedAllowQueryACL(CIMClient cimClient) throws CIMException { Enumeration enum = null; try{ enum = cimClient.associators(this.cimObjectPath, CIM_ASSOCIATOR_CLASS_ALLOW_QUERY_ACL_FOR_ZONE, DNSAddressMatchList.CIM_CLASS_NAME, "Element","Setting",false,false,null); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } ArrayList aclList = new ArrayList(); while (enum.hasMoreElements()) { CIMInstance dummyInstance = (CIMInstance) enum.nextElement(); try { aclList.add(new DNSAddressMatchList(dummyInstance, dummyInstance.getObjectPath())); } catch (ObjectCreationException e){ System.out.println("Tried to create an ACL from null value"); } catch (InvalidCimClassException e){ System.out.println("Cim Instance is not of type "+DNSAddressMatchList.CIM_CLASS_NAME); } } return aclList; } /**Gets the associated Transfer ACL names * @param cimClient * @return An ArrayList of ObjectPaths * @throws CIMException */ public ArrayList getAssociatedAllowTransferACLNames(CIMClient cimClient) throws CIMException { Enumeration enum = null; try{ enum = cimClient.associatorNames(this.cimObjectPath, CIM_ASSOCIATOR_CLASS_ALLOW_TRANSFER_ACL_FOR_ZONE, DNSAddressMatchList.CIM_CLASS_NAME, "Element","Setting"); } catch (CIMException e){ System.out.println(e.getMessage()); throw e; } ArrayList aclNamesList = new ArrayList(); while (enum.hasMoreElements()) { aclNamesList.add(enum.nextElement()); } return aclNamesList; } /**Gets the associated Transfer ACL * @param cimClient * @return An ArrayList of DNSAddressMatchList * @throws CIMException */ public ArrayList getAssociatedAllowTransferACL(CIMClient cimClient) throws CIMException { Enumeration enum = null; try{ enum = cimClient.associators(this.cimObjectPath, CIM_ASSOCIATOR_CLASS_ALLOW_TRANSFER_ACL_FOR_ZONE, DNSAddressMatchList.CIM_CLASS_NAME, "Element","Setting",false,false,null); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } ArrayList aclList = new ArrayList(); while (enum.hasMoreElements()) { CIMInstance dummyInstance = (CIMInstance) enum.nextElement(); try { aclList.add(new DNSAddressMatchList(dummyInstance, dummyInstance.getObjectPath())); } catch (ObjectCreationException e){ System.out.println("Tried to create an ACL from null value"); } catch (InvalidCimClassException e){ System.out.println("Cim Instance is not of type "+DNSAddressMatchList.CIM_CLASS_NAME); } } return aclList; } /**Gets the "Contact" field of the dns zone * @return * @throws PropertyNotFoundException */ public String getContact() throws PropertyNotFoundException { String tmp = null; CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_CONTACT); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_CONTACT + " not found"); throw new PropertyNotFoundException("Property " + CIM_PROPERTY_CONTACT + " not found"); } if (property.getValue() == null) { return null; } tmp = (String)property.getValue().getValue(); try{ tmp = tmp.replaceFirst("\\.","@"); }catch(Exception e){ } return tmp; } /** * @return The Serial Number */ public String getSoaSN() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_SN); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_SN + " not found"); throw new PropertyNotFoundException("Property " + CIM_PROPERTY_SN + " not found"); } if (property.getValue() == null) { return null; } return (String)property.getValue().getValue(); } /** * @return The Server */ public String getSoaServer() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_SERVER); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_SERVER + " not found"); throw new PropertyNotFoundException("Property " + CIM_PROPERTY_SERVER + " not found"); } if (property.getValue() == null) { return null; } return (String)property.getValue().getValue(); } /** * @return The refresh time in seconds after a resource record is refreshed */ public Integer getSoaRefresh() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_REFRESH); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_REFRESH + " not found"); throw new PropertyNotFoundException("Propertry " + CIM_PROPERTY_REFRESH + " not found"); } CIMValue propertyValue = property.getValue(); if (propertyValue == null) { return null; } UnsignedInt32 propertyIntValue = (UnsignedInt32)propertyValue.getValue(); if (propertyIntValue == null) { return null; } return new Integer(propertyIntValue.intValue()); } /** * @return Time in seconds after a resource record is retried */ public Integer getSoaRetry() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_RETRY); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_RETRY + " not found"); throw new PropertyNotFoundException("Propertry " + CIM_PROPERTY_RETRY + " not found"); } CIMValue propertyValue = property.getValue(); if (propertyValue == null) { return null; } UnsignedInt32 propertyIntValue = (UnsignedInt32)propertyValue.getValue(); if (propertyIntValue == null) { return null; } return new Integer(propertyIntValue.intValue()); } /** * @return Time in seconds after a resource record expires */ public Integer getSoaExpire() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_EXPIRE); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_EXPIRE + " not found"); throw new PropertyNotFoundException("Propertry " + CIM_PROPERTY_EXPIRE + " not found"); } CIMValue propertyValue = property.getValue(); if (propertyValue == null) { return null; } UnsignedInt32 propertyIntValue = (UnsignedInt32)propertyValue.getValue(); if (propertyIntValue == null) { return null; } return new Integer(propertyIntValue.intValue()); } /** * @return The negative caching time to live */ public Integer getSoaNCTTL() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_NCTTL); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_NCTTL + " not found"); throw new PropertyNotFoundException("Propertry " + CIM_PROPERTY_NCTTL + " not found"); } CIMValue propertyValue = property.getValue(); if (propertyValue == null) { return null; } UnsignedInt32 propertyIntValue = (UnsignedInt32)propertyValue.getValue(); if (propertyIntValue == null) { return null; } return new Integer(propertyIntValue.intValue()); } /** * @return The forwarders data * @throws PropertyNotFoundException */ public Object[] getForwarders() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_FORWARDERS); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_FORWARDERS + " not found"); throw new PropertyNotFoundException("Property " + CIM_PROPERTY_FORWARDERS + " not found"); } if (property.getValue() == null) { return null; } Vector v = (Vector) property.getValue().getValue(); return v.toArray(); } /** * @return The forward option as a Short * @throws PropertyNotFoundException */ public Short getForward() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_FORWARD); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_FORWARD + " not found"); throw new PropertyNotFoundException("Propertry " + CIM_PROPERTY_FORWARD + " not found"); } CIMValue propertyValue = property.getValue(); if (propertyValue == null) { return null; } UnsignedInt16 propertyIntValue = (UnsignedInt16)propertyValue.getValue(); if (propertyIntValue == null) { return null; } return new Short(propertyIntValue.shortValue()); } /**The forward option as a String * @return * @throws PropertyNotFoundException */ public String getForwardString() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_FORWARD); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_FORWARD + " not found"); throw new PropertyNotFoundException("Propertry " + CIM_PROPERTY_FORWARD + " not found"); } CIMValue propertyValue = property.getValue(); if (propertyValue == null) { return null; } UnsignedInt16 propertyIntValue = (UnsignedInt16)propertyValue.getValue(); if (propertyIntValue == null) { return null; } if (propertyIntValue.shortValue() > 0 && propertyIntValue.shortValue() < CIM_VALUEMAP_FORWARD.length) { return CIM_VALUEMAP_FORWARD[propertyIntValue.shortValue()]; } return CIM_VALUEMAP_FORWARD[0]; } /**Sets the "Contact" field of the dns zone. Call modifyInstance * later to commit the changes * @param contact */ public void setContact(String contact) { String tmp = contact; tmp = tmp.replaceFirst("@","."); CIMValue updatedValue = new CIMValue(tmp, new CIMDataType(CIMDataType.STRING)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_CONTACT); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the "SerialNumber" field of the dns zone. Call modifyInstance * later to commit the changes * @param sn */ public void setSoaSN(String sn){ CIMValue updatedValue = new CIMValue(sn, new CIMDataType(CIMDataType.STRING)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_SN); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the "Server" field of the dns zone. Call modifyInstance * later to commit the changes * @param sn */ public void setSoaServer(String server){ CIMValue updatedValue = new CIMValue(server, new CIMDataType(CIMDataType.STRING)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_SERVER); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the "Refresh" field of the dns zone. Call modifyInstance * later to commit the changes * @param refresh */ public void setSoaRefresh(Integer refresh){ CIMValue updatedValue = new CIMValue(new UnsignedInt32(refresh.intValue()),new CIMDataType(CIMDataType.UINT32)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_REFRESH); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the "Retry" field of the dns zone. Call modifyInstance * later to commit the changes * @param retry */ public void setSoaRetry(Integer retry){ CIMValue updatedValue = new CIMValue(new UnsignedInt32(retry.intValue()),new CIMDataType(CIMDataType.UINT32)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_RETRY); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the "Expire" field of the dns zone. Call modifyInstance * later to commit the changes * @param expire */ public void setSoaExpire(Integer expire){ CIMValue updatedValue = new CIMValue(new UnsignedInt32(expire.intValue()),new CIMDataType(CIMDataType.UINT32)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_EXPIRE); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the "NegativeCachingTTL" field of the dns zone. Call modifyInstance * later to commit the changes * @param ncttl */ public void setSoaNCTTL(Integer ncttl){ CIMValue updatedValue = new CIMValue(new UnsignedInt32(ncttl.intValue()),new CIMDataType(CIMDataType.UINT32)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_NCTTL); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the forward attribute. Call modifyInstance * later to commit the changes * @param type * @throws InvalidPropertyValueException */ public void setForward(Short value) throws InvalidPropertyValueException { if(value.shortValue()<0 || value.shortValue()>CIM_VALUEMAP_FORWARD.length){ System.out.println("Invalid "+CIM_PROPERTY_FORWARD); throw new InvalidPropertyValueException("Invalid "+CIM_PROPERTY_FORWARD); } CIMValue updatedValue = new CIMValue(new UnsignedInt16(value.shortValue()),new CIMDataType(CIMDataType.UINT16)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_FORWARD); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the forward attribute. Call modifyInstane to commit changes * @param type * @throws InvalidPropertyValueException */ public void setForward(String type) throws InvalidPropertyValueException { short pos = this.search(CIM_VALUEMAP_FORWARD,type); if(pos==-1) { System.out.println("Invalid "+CIM_PROPERTY_FORWARD); throw new InvalidPropertyValueException("Invalid "+CIM_PROPERTY_FORWARD); } CIMValue updatedValue = new CIMValue(new UnsignedInt16(pos),new CIMDataType(CIMDataType.UINT16)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_FORWARD); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets forwarders * @param addressList */ public void setForwarders(String[] addressList){ CIMValue updatedValue = new CIMValue(addressList, new CIMDataType(CIMDataType.STRING_ARRAY)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_FORWARDERS); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } public static boolean checkProperty(String property, Object value){ try{ if(property.equals(CIM_PROPERTY_TYPE)){ if (value != null && ((Boolean)value).booleanValue()) return true; else return false; }else if(property.equals(CIM_PROPERTY_CONTACT)) return validateEmail((String)value); else if(property.equals(CIM_PROPERTY_RRFILE) || property.equals(CIM_PROPERTY_SN) || property.equals(CIM_PROPERTY_NAME) || property.equals(CIM_PROPERTY_SERVER)){ if (value != null && ((String)value).trim().length() > 0) return true; else return false; }else if(property.equals(CIM_PROPERTY_REFRESH) || property.equals(CIM_PROPERTY_RETRY) || property.equals(CIM_PROPERTY_EXPIRE) || property.equals(CIM_PROPERTY_NCTTL)){ if(value instanceof Integer && ((Integer)value).intValue()>=0) return true; else return false; }else if(property.equals(CIM_PROPERTY_FORWARDERS)) return validateAddressList((String[]) value); return false; }catch(Exception e){ e.printStackTrace(); return false; } } private static boolean validateEmail(String value) { if (value.indexOf('@') == -1) { return false; } return true; } /**Checks address list entries. Works only for ip addresses yet. * @param l * @return */ private static boolean validateAddressList(String[] l){ String s = null; String[] t = null; for (int i=0;i<l.length;i++){ s = l[i]; t = s.split("\\."); if(t.length!=4){ if(s.indexOf(":")<0) return false; } } return true; } } --- NEW FILE: DNSAddressMatchList.java --- /** * DNSAddressMatchList.java * * (C) Copyright IBM Corp. 2005 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://www.opensource.org/licenses/cpl1.0.php * * Author: Rodrigo Ceron <rc...@br...> * * Contributors: **/ /* * Created on May 26, 2005, ceron */ package org.sblim.wbemsmt.dns.bl.fco; import java.util.ArrayList; import java.util.Enumeration; import java.util.Vector; import org.sblim.wbem.cim.CIMClass; import org.sblim.wbem.cim.CIMDataType; import org.sblim.wbem.cim.CIMException; import org.sblim.wbem.cim.CIMInstance; import org.sblim.wbem.cim.CIMObjectPath; import org.sblim.wbem.cim.CIMProperty; import org.sblim.wbem.cim.CIMValue; import org.sblim.wbem.cim.UnsignedInt16; import org.sblim.wbem.client.CIMClient; import org.sblim.wbemsmt.exception.InvalidCimClassException; import org.sblim.wbemsmt.exception.InvalidParameterException; import org.sblim.wbemsmt.exception.InvalidPropertyValueException; import org.sblim.wbemsmt.exception.ObjectCreationException; import org.sblim.wbemsmt.exception.PropertyNotFoundException; public class DNSAddressMatchList extends DNSCommonBase { public final static String CIM_CLASS_NAME = "Linux_DnsAddressMatchList"; public final static String CIM_PROPERTY_SERVICENAME = "ServiceName"; public final static String CIM_PROPERTY_NAME = "Name"; public final static String CIM_PROPERTY_ADDRESSLIST = "AddressList"; public final static String CIM_PROPERTY_ADDRESSLISTTYPE = "AddressListType"; public final static String[] CIM_VALUEMAP_ADDRESSLISTTYPE = {"Unknown","PreDefined", "IPv4","IPv6","IPPrefix","Key","AddressMatchList","NestedAddressMatchList"}; public final static short ADDRESS_LIST_TYPE_UNKNOWN = 0; public final static short ADDRESS_LIST_TYPE_PREDEFINED = 1; public final static short ADDRESS_LIST_TYPE_IPV4 = 2; public final static short ADDRESS_LIST_TYPE_IPV6 = 3; public final static short ADDRESS_LIST_TYPE_IPPREFIX = 4; public final static short ADDRESS_LIST_TYPE_KEY = 5; public final static short ADDRESS_LIST_TYPE_ADDRESSMATCHLIST = 6; public final static short ADDRESS_LIST_TYPE_NESTEDADDRESSMATCHLIST = 7; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_UPDATE_ACL_FOR_ZONE = "Linux_DnsAllowUpdateACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_QUERY_ACL_FOR_ZONE = "Linux_DnsAllowQueryACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_TRANSFER_ACL_FOR_ZONE = "Linux_DnsAllowTransferACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_NOTIFY_ACL_FOR_ZONE = "Linux_DnsAllowNotifyACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_QUERY_ACL_FOR_SERVICE = "Linux_DnsQueryACLForService"; public final static String CIM_ASSOCIATOR_CLASS_XFER_ACL_FOR_SERVICE = "Linux_DnsTransferACLForService"; public final static String CIM_ASSOCIATOR_CLASS_RECURSION_ACL_FOR_SERVICE = "Linux_DnsRecursionACLForService"; public final static String CIM_ASSOCIATOR_CLASS_NOTIFY_ACL_FOR_SERVICE = "Linux_DnsNotifyACLForService"; public final static String CIM_ASSOCIATOR_CLASS_BLACKHOLE_ACL_FOR_SERVICE = "Linux_DnsBlackholeACLForService"; public final static String CIM_ASSOCIATOR_CLASS_ACL_IN_DNSSERVICE = "Linux_DnsAddressMatchListOfService"; public final static String[] PREDEFINED_ACLS = {"any","none","localhost","localnets"}; private final static boolean DEBUG = true; /**Creates an Addres Match List object from a cim Instance * @param cimInstance * @param cimObjectPath * @throws ObjectCreationException * @throws InvalidCimClassException */ public DNSAddressMatchList(CIMInstance cimInstance, CIMObjectPath cimObjectPath) throws ObjectCreationException, InvalidCimClassException { if (cimInstance==null || cimObjectPath == null) { throw new ObjectCreationException("Null instance passed"); } if (!CIM_CLASS_NAME.equals(cimInstance.getClassName())) { throw new InvalidCimClassException("Cim Instance's class must be "+CIM_CLASS_NAME); } this.cimInstance = cimInstance; this.original_cimInstance = (CIMInstance)cimInstance.clone(); this.cimObjectPath = cimObjectPath; } /**Creates a new Address Match List instance. This is not reflected into the * cim server yet, call createInstance later. * @param cimClient * @throws CIMException */ public DNSAddressMatchList(CIMClient cimClient) throws CIMException { try{ this.cimObjectPath = new CIMObjectPath(CIM_CLASS_NAME); CIMClass cimClass = cimClient.getClass(this.cimObjectPath, false, true, true); this.cimInstance = cimClass.newInstance(); this.original_cimInstance = (CIMInstance)cimInstance.clone(); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } } /** Returns the instance's names of the address match lists in the server * @param cimClient * @return An ArrayList of CIMObjectPath objects * @throws CIMException */ public static ArrayList enumerateInstanceNames(CIMClient cimClient) throws CIMException { ArrayList cimInstanceNamesList = new ArrayList(); Enumeration enum = null; try{ enum = cimClient.enumerateInstanceNames(new CIMObjectPath(CIM_CLASS_NAME)); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } CIMObjectPath cimObjectPath = null; while (enum.hasMoreElements()) { cimObjectPath = (CIMObjectPath) enum.nextElement(); cimInstanceNamesList.add(cimObjectPath); } return cimInstanceNamesList; } /** Returns the instances of address match lists that are in the cim * server * @param cimClient * @return An ArrayList of AddressMatchList objects * @throws CIMException */ public static ArrayList enumerateInstances(CIMClient cimClient) throws CIMException { ArrayList cimInstanceList = new ArrayList(); Enumeration enum = null; try{ enum = cimClient.enumerateInstances(new CIMObjectPath(CIM_CLASS_NAME)); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } CIMInstance cimInstance = null; while (enum.hasMoreElements()) { cimInstance = (CIMInstance) enum.nextElement(); try { cimInstanceList.add(new DNSAddressMatchList(cimInstance, cimInstance.getObjectPath())); } catch(ObjectCreationException e) { System.out.println("Null Cim Instance passed!"); } catch(InvalidCimClassException e){ System.out.println("Cim Instance's class must be "+CIM_CLASS_NAME); } } return cimInstanceList; } /**Gets an address match list from the cim server * @param cimClient * @param cimObjectPath * @return An address match list * @throws CIMException * @throws InvalidParameterException */ public static DNSAddressMatchList getInstance(CIMClient cimClient, CIMObjectPath cimObjectPath) throws CIMException, InvalidParameterException { CIMInstance cimInstance = null; DNSAddressMatchList aml = null; if (cimObjectPath == null) { throw new InvalidParameterException("Null ObjectPath passed!"); } try{ cimInstance = cimClient.getInstance(cimObjectPath); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } try { aml = new DNSAddressMatchList(cimInstance, cimObjectPath); } catch (ObjectCreationException e) { System.out.println("Returned Cim Instance was null"); return null; } catch (InvalidCimClassException e){ System.out.println("ObjectPath is not a path to a "+CIM_CLASS_NAME); return null; } return aml; } /**Creates a new dns address match list * @param cimClient * @param aml * @return * @throws CIMException * @throws InvalidParameterException */ public static DNSAddressMatchList createInstance(CIMClient cimClient, DNSAddressMatchList aml) throws CIMException, InvalidParameterException { DNSAddressMatchList naml = null; CIMObjectPath cimObjectPath = null; if (aml == null || aml.getCimInstance() == null) { throw new InvalidParameterException("Invalid Address Match List passed for creation"); } try{ cimObjectPath = cimClient.createInstance(aml.getCimObjectPath(), aml.getCimInstance()); }catch (CIMException e){ System.out.println(e.getMessage()); throw e; } try { naml = getInstance(cimClient,cimObjectPath); }catch(Exception e){ System.out.println("Error while retrieving created ACL!"); } return naml; } /**Gets associated dns service names * @param cimClient * @return An ArrayList of CIMObjectPath * @throws CIMException */ public ArrayList getAssociatedDnsServiceNames(CIMClient cimClient) throws CIMException { //we don't want to know which service the ACL belongs to. We want only //which are being globally used String[] associations = {CIM_ASSOCIATOR_CLASS_BLACKHOLE_ACL_FOR_SERVICE, CIM_ASSOCIATOR_CLASS_NOTIFY_ACL_FOR_SERVICE, CIM_ASSOCIATOR_CLASS_QUERY_ACL_FOR_SERVICE, CIM_ASSOCIATOR_CLASS_RECURSION_ACL_FOR_SERVICE, CIM_ASSOCIATOR_CLASS_XFER_ACL_FOR_SERVICE}; Enumeration enum = null; ArrayList serviceList = new ArrayList(); for(int i=0;i<associations.length;i++){ try{ enum = cimClient.associatorNames(this.cimObjectPath,associations[i], DNSService.CIM_CLASS_NAME, "Dependent","Antecedent"); } catch (CIMException e){ System.out.println(e.getMessage()); throw e; } while (enum.hasMoreElements()) { serviceList.add(enum.nextElement()); } } return serviceList; } /**Gets associated dns service instances * @param cimClient * @return An ArrayList of DNSService * @throws CIMException */ public ArrayList getAssociatedDnsServices(CIMClient cimClient) throws CIMException { //we don't want to know which service the ACL belongs to. We want only //which are being globally used String[] associations = {CIM_ASSOCIATOR_CLASS_BLACKHOLE_ACL_FOR_SERVICE, CIM_ASSOCIATOR_CLASS_NOTIFY_ACL_FOR_SERVICE, CIM_ASSOCIATOR_CLASS_QUERY_ACL_FOR_SERVICE, CIM_ASSOCIATOR_CLASS_RECURSION_ACL_FOR_SERVICE, CIM_ASSOCIATOR_CLASS_XFER_ACL_FOR_SERVICE}; Enumeration enum = null; ArrayList serviceList = new ArrayList(); for(int i=0;i<associations.length;i++){ try{ enum = cimClient.associators(this.cimObjectPath,associations[i], DNSService.CIM_CLASS_NAME, "Dependent","Antecedent",false,false,null); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } while (enum.hasMoreElements()) { CIMInstance dummyInstance = (CIMInstance) enum.nextElement(); try { serviceList.add(new DNSService(dummyInstance, dummyInstance.getObjectPath())); } catch (ObjectCreationException e){ System.out.println("Tried to create a DNSService from null value"); } catch (InvalidCimClassException e){ System.out.println("Cim Instance is not of type "+DNSService.CIM_CLASS_NAME); } } } return serviceList; } /**Gets the names of zones that use this address match list * @param cimClient * @return An ArrayList of CIMObjectPath objects * @throws CIMException */ public ArrayList getAssociatedZoneNames(CIMClient cimClient) throws CIMException { String[] associations = {CIM_ASSOCIATOR_CLASS_ALLOW_NOTIFY_ACL_FOR_ZONE, CIM_ASSOCIATOR_CLASS_ALLOW_QUERY_ACL_FOR_ZONE, CIM_ASSOCIATOR_CLASS_ALLOW_TRANSFER_ACL_FOR_ZONE, CIM_ASSOCIATOR_CLASS_ALLOW_UPDATE_ACL_FOR_ZONE}; Enumeration enum = null; ArrayList zoneList = new ArrayList(); for(int i=0;i<associations.length;i++){ try{ enum = cimClient.associatorNames(this.cimObjectPath,associations[i],DNSZone.CIM_CLASS_NAME, "Setting","Element"); } catch (CIMException e){ System.out.println(e.getMessage()); throw e; } while (enum.hasMoreElements()) { zoneList.add(enum.nextElement()); } } return zoneList; } /**Gets instances of the zones that use this address match list * @param cimClient * @return An ArrayList of DNSZone objects * @throws CIMException */ public ArrayList getAssociatedZones(CIMClient cimClient) throws CIMException { String[] associations = {CIM_ASSOCIATOR_CLASS_ALLOW_NOTIFY_ACL_FOR_ZONE, CIM_ASSOCIATOR_CLASS_ALLOW_QUERY_ACL_FOR_ZONE, CIM_ASSOCIATOR_CLASS_ALLOW_TRANSFER_ACL_FOR_ZONE, CIM_ASSOCIATOR_CLASS_ALLOW_UPDATE_ACL_FOR_ZONE}; Enumeration enum = null; ArrayList zoneList = new ArrayList(); for(int i=0;i<associations.length;i++){ try{ enum = cimClient.associators(this.cimObjectPath,associations[i],DNSZone.CIM_CLASS_NAME, "Setting","Element",false,false,null); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } while (enum.hasMoreElements()) { CIMInstance dummyInstance = (CIMInstance) enum.nextElement(); try { zoneList.add(new DNSZone(dummyInstance, dummyInstance.getObjectPath())); } catch (ObjectCreationException e){ System.out.println("Tried to create a DNSZone from null value"); } catch (InvalidCimClassException e){ System.out.println("Cim Instance is not of type "+DNSZone.CIM_CLASS_NAME); } } } return zoneList; } /** * @return The service name * @throws PropertyNotFoundException */ public String getServiceName() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_SERVICENAME); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_SERVICENAME + " not found"); throw new PropertyNotFoundException("Property " + CIM_PROPERTY_SERVICENAME + " not found"); } if (property.getValue() == null) { return null; } return (String)property.getValue().getValue(); } /** * @return The name of the addres match list * @throws PropertyNotFoundException */ public String getName() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_NAME); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_NAME + " not found"); throw new PropertyNotFoundException("Property " + CIM_PROPERTY_NAME + " not found"); } if (property.getValue() == null) { return null; } return (String)property.getValue().getValue(); } /** * @return The address match list data * @throws PropertyNotFoundException */ public Object[] getAddressList() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_ADDRESSLIST); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_ADDRESSLIST + " not found"); throw new PropertyNotFoundException("Property " + CIM_PROPERTY_ADDRESSLIST + " not found"); } if (property.getValue() == null) { return null; } Vector v = (Vector) property.getValue().getValue(); return v.toArray(); } /** * @return The address match list type as a Short * @throws PropertyNotFoundException */ public Short getAddressListType() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_ADDRESSLISTTYPE); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_ADDRESSLISTTYPE + " not found"); throw new PropertyNotFoundException("Propertry " + CIM_PROPERTY_ADDRESSLISTTYPE + " not found"); } CIMValue propertyValue = property.getValue(); if (propertyValue == null) { return null; } UnsignedInt16 propertyIntValue = (UnsignedInt16)propertyValue.getValue(); if (propertyIntValue == null) { return null; } return new Short(propertyIntValue.shortValue()); } /**The address match list type as a String * @return * @throws PropertyNotFoundException */ public String getAddressListTypeString() throws PropertyNotFoundException { CIMProperty property = this.cimInstance.getProperty(CIM_PROPERTY_ADDRESSLISTTYPE); if (property == null) { System.out.println("Propertry " + CIM_PROPERTY_ADDRESSLISTTYPE + " not found"); throw new PropertyNotFoundException("Propertry " + CIM_PROPERTY_ADDRESSLISTTYPE + " not found"); } CIMValue propertyValue = property.getValue(); if (propertyValue == null) { return null; } UnsignedInt16 propertyIntValue = (UnsignedInt16)propertyValue.getValue(); if (propertyIntValue == null) { return null; } if (propertyIntValue.shortValue() > 0 && propertyIntValue.shortValue() < CIM_VALUEMAP_ADDRESSLISTTYPE.length) { return CIM_VALUEMAP_ADDRESSLISTTYPE[propertyIntValue.shortValue()]; } return CIM_VALUEMAP_ADDRESSLISTTYPE[0]; } /**Sets the "ServiceName" field of the address match list. Call modifyInstance * later to commit the changes * @param serviceName */ public void setServiceName(String serviceName){ CIMValue updatedValue = new CIMValue(serviceName, new CIMDataType(CIMDataType.STRING)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_SERVICENAME); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the "Name" field of the address match list. Call modifyInstance * later to commit the changes * @param name */ public void setName(String name){ CIMValue updatedValue = new CIMValue(name, new CIMDataType(CIMDataType.STRING)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_NAME); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } public void setAddressList(String[] addressList){ CIMValue updatedValue = new CIMValue(addressList, new CIMDataType(CIMDataType.STRING_ARRAY)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_ADDRESSLIST); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the address list type of the address match list. Call modifyInstance * later to commit the changes * @param type * @throws InvalidPropertyValueException */ public void setAddressListType(Short type) throws InvalidPropertyValueException { if(type.shortValue()<0 || type.shortValue()>CIM_VALUEMAP_ADDRESSLISTTYPE.length){ System.out.println("Invalid "+CIM_PROPERTY_ADDRESSLISTTYPE); throw new InvalidPropertyValueException("Invalid "+CIM_PROPERTY_ADDRESSLISTTYPE); } CIMValue updatedValue = new CIMValue(new UnsignedInt16(type.shortValue()),new CIMDataType(CIMDataType.UINT16)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_ADDRESSLISTTYPE); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } /**Sets the address list type. Call modifyInstane to commit changes * @param type * @throws InvalidPropertyValueException */ public void setAddressListType(String type) throws InvalidPropertyValueException { short pos = this.search(CIM_VALUEMAP_ADDRESSLISTTYPE,type); if(pos==-1) { System.out.println("Invalid "+CIM_PROPERTY_ADDRESSLISTTYPE); throw new InvalidPropertyValueException("Invalid "+CIM_PROPERTY_ADDRESSLISTTYPE); } CIMValue updatedValue = new CIMValue(new UnsignedInt16(pos),new CIMDataType(CIMDataType.UINT16)); CIMProperty currentProperty = this.cimInstance.getProperty(CIM_PROPERTY_ADDRESSLISTTYPE); if (currentProperty != null) { currentProperty.setValue(updatedValue); } } public boolean checkProperty(String property, Object value){ try { if (property.equals(CIM_PROPERTY_ADDRESSLISTTYPE)) { if (value != null && ((Short)value).shortValue()>0) return true; else return false; }else if (property.equals(CIM_PROPERTY_NAME) || property.equals(CIM_PROPERTY_SERVICENAME)) { if(((String)value).equals("any") || ((String)value).equals("localhost") || ((String)value).equals("none") || ((String)value).equals("localnets")) return false; if (value != null && ((String)value).trim().length() > 0) return true; else return false; }else if(property.equals(CIM_PROPERTY_ADDRESSLIST)) return validateAddressList((String[]) value); return false; } catch (Exception ex) { ex.printStackTrace(); return false; } } /**Checks address list entries. Works only for ip addresses yet. * @param l * @return */ private boolean validateAddressList(String[] l){ String s = null; String[] t = null; for (int i=0;i<l.length;i++){ s = l[i]; t = s.split("\\."); if(t.length!=4){ if(s.indexOf(":")<0) return false; } } return true; } } --- NEW FILE: DNSSlaveZone.java --- /** * DNSSlaveZone.java * * (C) Copyright IBM Corp. 2005 * * THIS FILE IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. * * You can obtain a current copy of the Common Public License from * http://www.opensource.org/licenses/cpl1.0.php * * Author: Rodrigo Ceron <rc...@br...> * * Contributors: **/ /* * Created on May 17, 2005, ceron */ package org.sblim.wbemsmt.dns.bl.fco; import java.util.ArrayList; import java.util.Enumeration; import java.util.Vector; import org.sblim.wbem.cim.CIMClass; import org.sblim.wbem.cim.CIMDataType; import org.sblim.wbem.cim.CIMException; import org.sblim.wbem.cim.CIMInstance; import org.sblim.wbem.cim.CIMObjectPath; import org.sblim.wbem.cim.CIMProperty; import org.sblim.wbem.cim.CIMValue; import org.sblim.wbem.cim.UnsignedInt16; import org.sblim.wbem.client.CIMClient; import org.sblim.wbemsmt.exception.InvalidCimClassException; import org.sblim.wbemsmt.exception.InvalidParameterException; import org.sblim.wbemsmt.exception.InvalidPropertyValueException; import org.sblim.wbemsmt.exception.ObjectCreationException; import org.sblim.wbemsmt.exception.PropertyNotFoundException; //import org.sblim.wbemsmt.exception.PropertyNotFoundException; /** * Author ceron * */ public class DNSSlaveZone extends DNSZone { public final static String CIM_CLASS_NAME = "Linux_DnsSlaveZone"; public final static String CIM_PROPERTY_FORWARD = "Forward"; public final static String CIM_PROPERTY_FORWARDERS = "Forwarders"; public final static String CIM_ASSOCIATOR_CLASS_IPADDRESS = "Linux_DnsMastersOfSlaveZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_NOTIFY_ACL_FOR_ZONE = "Linux_DnsAllowNotifyACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_QUERY_ACL_FOR_ZONE = "Linux_DnsAllowQueryACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_ALLOW_TRANSFER_ACL_FOR_ZONE = "Linux_DnsAllowTransferACLForZone"; public final static String CIM_ASSOCIATOR_CLASS_BLACKHOLE_ACL_FOR_ZONE = "Linux_DnsBlackholeACLForZone"; public final static String[] CIM_VALUEMAP_FORWARD = {"Unknown","Only","First"}; public final static short FORWARD_UNKNOWN = 0; public final static short FORWARD_ONLY = 1; public final static short FORWARD_FIRST = 2; /**Creates a DNSSlaveZone Object from a cim instance * @param cimInstance * @param cimObjectPath * @throws ObjectCreationException * @throws InvalidCimClassException */ public DNSSlaveZone(CIMInstance cimInstance, CIMObjectPath cimObjectPath) throws ObjectCreationException, InvalidCimClassException { super(cimInstance,cimObjectPath); this.className = CIM_CLASS_NAME; } /**Creates a new DNSSlaveZone instance. This is not reflected into the * cim server yet, call createInstance later * @param cimClient * @throws CIMException */ public DNSSlaveZone(CIMClient cimClient) throws CIMException { super(cimClient); this.className = CIM_CLASS_NAME; try{ this.cimObjectPath = new CIMObjectPath(this.className); CIMClass cimClass = cimClient.getClass(this.cimObjectPath, false, true, true); this.cimInstance = cimClass.newInstance(); this.original_cimInstance = (CIMInstance)cimInstance.clone(); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } } /* (non-Javadoc) * @see com.ibm.wbem.smt.dns.DNSZone#enumerateInstanceNames(com.ibm.wbem.smt.CimClient) */ public static ArrayList enumerateInstanceNames(CIMClient cimClient) throws CIMException { ArrayList cimInstanceNamesList = new ArrayList(); Enumeration enum = null; try{ enum = cimClient.enumerateInstanceNames(new CIMObjectPath(CIM_CLASS_NAME)); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } CIMObjectPath cimObjectPath = null; while (enum.hasMoreElements()) { cimObjectPath = (CIMObjectPath) enum.nextElement(); cimInstanceNamesList.add(cimObjectPath); } return cimInstanceNamesList; } /* (non-Javadoc) * @see com.ibm.wbem.smt.dns.DNSZone#enumerateInstances(com.ibm.wbem.smt.CimClient) */ public static ArrayList enumerateInstances(CIMClient cimClient) throws CIMException { ArrayList cimInstanceList = new ArrayList(); Enumeration enum = null; CIMInstance cimInstance = null; try{ enum = cimClient.enumerateInstances(new CIMObjectPath(CIM_CLASS_NAME)); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } while (enum.hasMoreElements()) { cimInstance = (CIMInstance) enum.nextElement(); try { cimInstanceList.add(new DNSSlaveZone(cimInstance, cimInstance.getObjectPath())); } catch(ObjectCreationException e) { System.out.println("Null Cim Instance passed!"); } catch(InvalidCimClassException e){ System.out.println("Cim Instance's class must be "+CIM_CLASS_NAME); } } return cimInstanceList; } /* (non-Javadoc) * @see com.ibm.wbem.smt.dns.DNSZone#getInstance(com.ibm.wbem.smt.CimClient, javax.wbem.cim.CIMObjectPath) */ public static DNSZone getInstance(CIMClient cimClient, CIMObjectPath cimObjectPath) throws CIMException, InvalidParameterException { CIMInstance cimInstance = null; DNSSlaveZone zone = null; if (cimObjectPath == null) { throw new InvalidParameterException("Null ObjectPath passed!"); } try{ cimInstance = cimClient.getInstance(cimObjectPath); }catch (CIMException e){ System.out.println("Error within cim client"); throw e; } try { zone = new DNSSlaveZone(cimInstance, cimObjectPath); } catch (ObjectCreationException e) { System.out.println("Returned Cim Instance was null"); return null; } catch (InvalidCimClassException e){ System.out.println("ObjectPath is not a path to " + CIM_CLASS_NAME); return null; } return zone; } public static DNSSlaveZone createInstance(CIMClient cimClient, DNSSlaveZone dnsSlaveZone) throws CIMException, InvalidParameterException { DNSSlaveZone slaveZone = null; CIMObjectPath cimObjectPath = null; if (dnsSlaveZone == null || dnsSlaveZone.getCimInstance() == null) { throw new InvalidParameterException("Invalid Zone passed for creation"); } try{ cimObjectPath = cimClient.createInstance(dnsSlaveZone.getCimObjectPath(), dnsSlaveZone.getCimInstance()); }catch (CIMException e){ System.out.println(e.getMessage()); throw e; } try { slaveZone = (DNSSlaveZone) getInstance(cimClient,cimObjectPath); }catch(Exception e){ System.err.println("System internal error while retrieving created DNS zone"); } return slaveZone; } /**Gets the associated Notify ACL names * @param cimClient * @return An ArrayList of ACL ObjectPaths * @throws CIMException */ public ArrayList getAssociatedAllowNotifyACLNames(CIMClient cimClient) throws CIMException { Enumeration enum = null; try{ enum = cimClient.associatorNames(this.cimObjectPath, CIM_ASSOCIATOR_CLASS_ALLOW_NOTIFY_ACL_FOR_ZONE, DNSAddressMatchList.CIM_CLASS_NAME, "Element","Setting"); } catch (CIMException e){ System.out.println(e.getMessage()); ... [truncated message content] |