예제 #1
0
 /*
  * Will read a number of SchoolInfo Objects from a XML file. The location of the XML File is stored in the provider.properties file
  * in the "provider.school.file.location" property.
  */
 public SchoolProvider() {
   super();
   logger.debug("Constructor for SchoolProvider has been called.");
   if (schools == null) {
     logger.debug(
         "Constructor for SchoolProvider called for the first time. Try to load students from XML file...");
     // Load all school so that we can do some real stuff here.
     String schoolFile =
         getServiceProperties().getPropertyAsString("provider.school.file.location", null);
     if (schoolFile != null) {
       try {
         String inputXML = FileReaderWriter.getFileContent(schoolFile, ModelObjectConstants.UTF_8);
         XSchoolCollectionType schoolList =
             (XSchoolCollectionType)
                 getUnmarshaller()
                     .unmarshalFromXML(inputXML, getMultiObjectClassInfo().getObjectType());
         if ((schoolList != null) && (schoolList.getXSchool() != null)) {
           schools = new HashMap<String, XSchoolType>();
           for (XSchoolType schoolInfo : schoolList.getXSchool()) {
             schools.put(schoolInfo.getRefId(), schoolInfo);
           }
           logger.debug("Loaded " + schools.size() + " schools into memory.");
         }
       } catch (Exception ex) {
         ex.printStackTrace();
         logger.debug("Loaded " + schools.size() + " schools into memory.");
       }
     }
     // If schools are still null then something must have failed and would have been logged. For
     // the purpose of making things work ok we initialise the students hashmap now. It will avoid
     // null pointer errors.
     if (schools == null) {
       schools = new HashMap<String, XSchoolType>();
     }
   }
 }
  public StudentPersonalProvider() {
    super();

    logger.debug("Constructor for StudentPersonalProvider has been called.");
    if (students == null) {
      logger.debug(
          "Constructor for StudentPersonalProvider called for the first time. Try to load students from XML file...");

      // Load all students so that we can do some real stuff here.
      String studentFile =
          getServiceProperties().getPropertyAsString("provider.student.file.location", null);
      if (studentFile != null) {
        //				String inputXML = FileReaderWriter.getFileContent(studentFile,
        // getProviderEnvironment().getCharsetEncoding());
        String inputXML = FileReaderWriter.getFileContent(studentFile, ModelObjectConstants.UTF_8);
        try {
          StudentPersonalCollectionType studentList =
              (StudentPersonalCollectionType)
                  getUnmarshaller()
                      .unmarshalFromXML(inputXML, getMultiObjectClassInfo().getObjectType());
          if ((studentList != null) && (studentList.getStudentPersonal() != null)) {
            students = new HashMap<String, StudentPersonalType>();
            for (StudentPersonalType studentPersonal : studentList.getStudentPersonal()) {
              //							studentPersonal.setRefId(UUIDGenerator.getUUID());
              students.put(studentPersonal.getRefId(), studentPersonal);
            }
            logger.debug("Loaded " + students.size() + " Students into memory.");
          }
        } catch (UnmarshalException ex) {
          ex.printStackTrace();
        } catch (UnsupportedMediaTypeException ex) {
          ex.printStackTrace();
        }
      }
    }

    if (teachingGroupStudents == null) {
      logger.debug("Try to load students for teaching group from XML file...");

      // Load all students so that we can do some real stuff here.
      String fileName =
          getServiceProperties().getPropertyAsString("provider.teachinggroup.file.location", null);
      if (fileName != null) {
        String inputXML = FileReaderWriter.getFileContent(fileName, ModelObjectConstants.UTF_8);
        try {
          TeachingGroupCollectionType classes =
              (TeachingGroupCollectionType)
                  getUnmarshaller()
                      .unmarshalFromXML(
                          inputXML, ModelObjectConstants.TEACHING_GROUPS.getObjectType());
          if ((classes != null) && (classes.getTeachingGroup() != null)) {
            // Get student list of first teaching group
            JAXBElement<StudentList> jaxbClassStudents =
                classes.getTeachingGroup().get(0).getStudentList();
            if (jaxbClassStudents != null) {
              teachingGroupStudents = new HashMap<String, StudentPersonalType>();
              StudentList classStudents = jaxbClassStudents.getValue();
              for (TeachingGroupStudent student : classStudents.getTeachingGroupStudent()) {
                teachingGroupStudents.put(
                    student.getStudentPersonalRefId().getValue(),
                    students.get(student.getStudentPersonalRefId().getValue()));
              }
            }
            logger.debug(
                "Loaded "
                    + teachingGroupStudents.size()
                    + " teaching group students for a class into memory.");
          }
        } catch (UnmarshalException ex) {
          ex.printStackTrace();
        } catch (UnsupportedMediaTypeException ex) {
          ex.printStackTrace();
        }
      }
    }

    // If students are still null then something must have failed and would have been logged.
    // For the purpose of making things work ok we initialise the students hashmap now. It will
    // avoid null pointer errors.
    if (students == null) {
      students = new HashMap<String, StudentPersonalType>();
    }
    if (teachingGroupStudents == null) {
      teachingGroupStudents = new HashMap<String, StudentPersonalType>();
    }
  }