📄 jmpiassociationprovider.java
字号:
System.err.println ("JMPIAssociationProvider::associators: assocName = " + assocName); System.err.println ("JMPIAssociationProvider::associators: objectName = " + objectName); System.err.println ("JMPIAssociationProvider::associators: resultClass = " + resultClass); System.err.println ("JMPIAssociationProvider::associators: role = " + role); System.err.println ("JMPIAssociationProvider::associators: resultRole = " + resultRole); System.err.println ("JMPIAssociationProvider::associators: includeQualifiers = " + includeQualifiers); System.err.println ("JMPIAssociationProvider::associators: includeClassOrigin = " + includeClassOrigin); System.err.println ("JMPIAssociationProvider::associators: propertyList = " + propertyList); } // Enusre that the namespace is valid if (!assocName.getNameSpace ().equalsIgnoreCase (NAMESPACE)) { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); } CIMObjectPath localObjectPath = new CIMObjectPath (objectName.getObjectName (), objectName.getKeys ()); localObjectPath.setHost (""); localObjectPath.setNameSpace (NAMESPACE); Vector vectorReturn = null; if (assocName.getObjectName ().equalsIgnoreCase (SAMPLE_TEACHERSTUDENT)) { vectorReturn = _associators (TSassociationInstances, localObjectPath, role, resultClass, resultRole); } else if (assocName.getObjectName ().equalsIgnoreCase (SAMPLE_ADVISORSTUDENT)) { vectorReturn = _associators (ASassociationInstances, localObjectPath, role, resultClass, resultRole); } else { throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS, assocName.getObjectName () + " is not supported"); } if (DEBUG) { System.err.println ("JMPIAssociationProvider::associators: returning " + vectorReturn.size () + " instances"); } return vectorReturn; } public Vector referenceNames (CIMObjectPath assocName, CIMObjectPath objectName, String role) throws CIMException { if (DEBUG) { System.err.println ("JMPIAssociationProvider::referenceNames: assocName = " + assocName); System.err.println ("JMPIAssociationProvider::referenceNames: objectName = " + objectName); System.err.println ("JMPIAssociationProvider::referenceNames: role = " + role); } // Enusre that the namespace is valid if (!assocName.getNameSpace ().equalsIgnoreCase (NAMESPACE)) { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); } CIMObjectPath localObjectPath = new CIMObjectPath (objectName.getObjectName (), objectName.getKeys ()); localObjectPath.setHost (""); localObjectPath.setNameSpace (NAMESPACE); // Filter the instances from the list of association instances against // the specified role filter // Vector resultInstances; if (assocName.getObjectName ().equalsIgnoreCase (SAMPLE_TEACHERSTUDENT)) { resultInstances = _filterAssociationInstancesByRole (TSassociationInstances, localObjectPath, role); } else if (assocName.getObjectName ().equalsIgnoreCase (SAMPLE_ADVISORSTUDENT)) { resultInstances = _filterAssociationInstancesByRole (ASassociationInstances, localObjectPath, role); } else { throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS, assocName.getObjectName () + " is not supported"); } Vector vectorReturn = new Vector (); // return the instance names for (int i = 0, si = resultInstances.size (); i < si; i++) { CIMObjectPath objectPath = ((CIMInstance)resultInstances.elementAt (i)).getObjectPath (); vectorReturn.addElement (objectPath); } if (DEBUG) { System.err.println ("JMPIAssociationProvider::referenceNames: returning " + vectorReturn.size () + " instances"); } return vectorReturn; } public Vector references (CIMObjectPath assocName, CIMObjectPath objectName, String role, boolean includeQualifiers, boolean includeClassOrigin, String[] propertyList) throws CIMException { if (DEBUG) { System.err.println ("JMPIAssociationProvider::references: assocName = " + assocName); System.err.println ("JMPIAssociationProvider::references: objectName = " + objectName); System.err.println ("JMPIAssociationProvider::references: role = " + role); System.err.println ("JMPIAssociationProvider::references: includeQualifiers = " + includeQualifiers); System.err.println ("JMPIAssociationProvider::references: includeClassOrigin = " + includeClassOrigin); System.err.println ("JMPIAssociationProvider::references: propertyList = " + propertyList); } // Enusre that the namespace is valid if (!assocName.getNameSpace ().equalsIgnoreCase (NAMESPACE)) { throw new CIMException (CIMException.CIM_ERR_INVALID_NAMESPACE); } CIMObjectPath localObjectPath = new CIMObjectPath (objectName.getObjectName (), objectName.getKeys ()); localObjectPath.setHost (""); localObjectPath.setNameSpace (NAMESPACE); // Filter the instances from the list of association instances against // the specified role filter // Vector resultInstances; if (assocName.getObjectName ().equalsIgnoreCase (SAMPLE_TEACHERSTUDENT)) { resultInstances = _filterAssociationInstancesByRole (TSassociationInstances, localObjectPath, role); } else if (assocName.getObjectName ().equalsIgnoreCase (SAMPLE_ADVISORSTUDENT)) { resultInstances = _filterAssociationInstancesByRole (ASassociationInstances, localObjectPath, role); } else { throw new CIMException (CIMException.CIM_ERR_INVALID_CLASS, assocName.getObjectName () + " is not supported"); } if (DEBUG) { System.err.println ("JMPIAssociationProvider::references: returning " + resultInstances.size () + " instances"); } return resultInstances; } private void createDefaultInstances () { // // create 4 instances of the SAMPLE_TEACHER class // teacherInstances.add (createInstance (SAMPLE_TEACHER, "Teacher1", 1)); teacherInstances.add (createInstance (SAMPLE_TEACHER, "Teacher2", 2)); teacherInstances.add (createInstance (SAMPLE_TEACHER, "Teacher3", 3)); teacherInstances.add (createInstance (SAMPLE_TEACHER, "Teacher4", 4)); // // create 3 instances of the SAMPLE_STUDENT class // studentInstances.add (createInstance (SAMPLE_STUDENT, "Student1", 1)); studentInstances.add (createInstance (SAMPLE_STUDENT, "Student2", 2)); studentInstances.add (createInstance (SAMPLE_STUDENT, "Student3", 3)); // // create the instances for the SAMPLE_TEACHERSTUDENT association class // (Teacher1, Student1) // (Teacher1, Student2) // (Teacher1, Student3) // (Teacher2, Student1) // (Teacher2, Student2) // (Teacher3, Student2) // (Teacher3, Student3) // (Teacher4, Student1) // TSassociationInstances.add (createTSAssociationInstance (getPath (teacherInstances, 0), getPath (studentInstances, 0))); TSassociationInstances.add (createTSAssociationInstance (getPath (teacherInstances, 0), getPath (studentInstances, 1))); TSassociationInstances.add (createTSAssociationInstance (getPath (teacherInstances, 0), getPath (studentInstances, 2))); TSassociationInstances.add (createTSAssociationInstance (getPath (teacherInstances, 1), getPath (studentInstances, 0))); TSassociationInstances.add (createTSAssociationInstance (getPath (teacherInstances, 1), getPath (studentInstances, 1))); TSassociationInstances.add (createTSAssociationInstance (getPath (teacherInstances, 2), getPath (studentInstances, 1))); TSassociationInstances.add (createTSAssociationInstance (getPath (teacherInstances, 2), getPath (studentInstances, 2))); TSassociationInstances.add (createTSAssociationInstance (getPath (teacherInstances, 3), getPath (studentInstances, 0))); // // create the instances for the SAMPLE_ADVISORSTUDENT association class // (Teacher1, Student1) // (Teacher1, Student2) // (Teacher2, Student3) // ASassociationInstances.add (createASAssociationInstance (getPath (teacherInstances, 0), getPath (studentInstances, 0))); ASassociationInstances.add (createASAssociationInstance (getPath (teacherInstances, 0), getPath (studentInstances, 1))); ASassociationInstances.add (createASAssociationInstance (getPath (teacherInstances, 1), getPath (studentInstances, 2))); } private CIMObjectPath getPath (Vector v, int i) { try { CIMInstance c = (CIMInstance)v.elementAt (i); return c.getObjectPath (); } catch (Exception e) { System.err.println ("JMPIAssociationProvider::getPath: Caught Exception " + e); } return null; } private CIMInstance createInstance (String className, String name, int id) { try { CIMProperty[] props = { new CIMProperty ("Name", new CIMValue (name)), /* @TBD: cimcli doesnt pass this in: className */ new CIMProperty ("Identifier", new CIMValue (new UnsignedInt8 (Integer.toString (id)))) /* @TBD: ... className */ }; CIMObjectPath cop = new CIMObjectPath (className, NAMESPACE); CIMInstance instance = new CIMInstance (className); for (int i = 0; i < props.length; i++) { instance.setProperty (props[i].getName (), props[i].getValue ()); cop.addKey (props[i].getName (), props[i].getValue ()); } cop.setHost (""); instance.setObjectPath (cop); return instance; } catch (CIMException e) { return null; } } private CIMInstance createTSAssociationInstance (CIMObjectPath ref1, CIMObjectPath ref2) { try { CIMProperty[] props = { new CIMProperty ("Teaches", new CIMValue (ref1)), new CIMProperty ("TaughtBy", new CIMValue (ref2)) }; CIMObjectPath cop = new CIMObjectPath (SAMPLE_TEACHERSTUDENT, NAMESPACE); CIMInstance instance = new CIMInstance (SAMPLE_TEACHERSTUDENT); for (int i = 0; i < props.length; i++) { instance.setProperty (props[i].getName (), props[i].getValue ()); cop.addKey (props[i].getName (), props[i].getValue ()); } cop.setHost (""); instance.setObjectPath (cop); return instance; } catch (CIMException e) { return null; } } private CIMInstance createASAssociationInstance (CIMObjectPath ref1, CIMObjectPath ref2) { try { CIMProperty[] props = { new CIMProperty ("Advises", new CIMValue (ref1)), new CIMProperty ("AdvisedBy", new CIMValue (ref2)) }; CIMObjectPath cop = new CIMObjectPath (SAMPLE_ADVISORSTUDENT, NAMESPACE); CIMInstance instance = new CIMInstance (SAMPLE_ADVISORSTUDENT); for (int i = 0; i < props.length; i++) { instance.setProperty (props[i].getName (), props[i].getValue ()); cop.addKey (props[i].getName (), props[i].getValue ()); } cop.setHost (""); instance.setObjectPath (cop); return instance; } catch (CIMException e) { return null; } } private CIMInstance _getInstance (Vector instances, CIMObjectPath localObjectPath) { Iterator iteratorInstances = instances.iterator (); while (iteratorInstances.hasNext ()) { CIMInstance elm = (CIMInstance)iteratorInstances.next (); CIMObjectPath elmPath = elm.getObjectPath ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -