Example usage for java.lang IllegalAccessError IllegalAccessError

List of usage examples for java.lang IllegalAccessError IllegalAccessError

Introduction

In this page you can find the example usage for java.lang IllegalAccessError IllegalAccessError.

Prototype

public IllegalAccessError(String s) 

Source Link

Document

Constructs an IllegalAccessError with the specified detail message.

Usage

From source file:com.rapidminer.gui.new_plotter.templates.PlotterTemplate.java

/**
 * Returns the I18N name of the {@link PlotterTemplate} as displayed in the GUI.
 * /*w w w  . j a v  a 2s . co m*/
 * @return the I18N name
 */
public static String getI18NName() {
    throw new IllegalAccessError("method must be implemented by each template so this method will be hidden!");
}

From source file:com.baidu.cc.web.rpc.ConfigServerServiceImpl.java

/**
 * ??id?? ???? IllegalAccessError./*from  w  w  w  . j  ava  2  s.  com*/
 * 
 * @param user
 *            ??
 * @param password
 *            ?
 * @param envId
 *            ?id
 * @return ?
 */
@Override
public Long getLastestConfigVersion(String user, String password, Long envId) {
    User u = authenticate(user, password);

    // should check authorization here by project
    authorizeEnv(u, envId);

    Version version = getLastestConfigVersion(envId);
    if (version == null) {
        throw new IllegalAccessError("No version under environemt id: " + envId);
    }

    return version.getId();
}

From source file:com.antsdb.saltedfish.util.UberUtil.java

@SuppressWarnings("unchecked")
public static <T> T clone(final T obj) throws CloneNotSupportedException {
    if (obj == null) {
        return null;
    }/*  w  w  w .  j  a v a2  s .c om*/
    if (obj instanceof Cloneable) {
        Class<?> clazz = obj.getClass();
        Method m;
        try {
            m = clazz.getMethod("clone", (Class[]) null);
        } catch (NoSuchMethodException ex) {
            throw new NoSuchMethodError(ex.getMessage());
        }
        try {
            return (T) m.invoke(obj, (Object[]) null);
        } catch (InvocationTargetException ex) {
            Throwable cause = ex.getCause();
            if (cause instanceof CloneNotSupportedException) {
                throw ((CloneNotSupportedException) cause);
            } else {
                throw new Error("Unexpected exception", cause);
            }
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        }
    } else {
        throw new CloneNotSupportedException();
    }
}

From source file:com.turt2live.xmail.engine.connection.PHPConnection2A.java

@SuppressWarnings("unchecked")
@Override//  www  .  j  av  a2s .  co m
public void init() {
    ServerResponse response = attemptRequest(RequestType.REQUEST_AUTH); // Start a request for auth
    if (response.getErrorCode() == 403) {
        throw new IllegalAccessError("xMail server denied authentication request");
    } else if (response.getErrorCode() < 0) {
        throw new IllegalAccessError("xMail server cannot be reached");
    }
    List<String> lines = attemptRequest(RequestType.INFORMATION).getLines();
    for (String line : lines) {
        JSONParser parser = new JSONParser();
        ContainerFactory containerFactory = new ContainerFactory() {
            @Override
            public List<Object> creatArrayContainer() {
                return new LinkedList<Object>();
            }

            @Override
            public Map<String, Object> createObjectContainer() {
                return new LinkedHashMap<String, Object>();
            }

        };

        Map<String, Object> map = new HashMap<String, Object>();

        try {
            Map<?, ?> json = (Map<?, ?>) parser.parse(line, containerFactory);
            Iterator<?> iter = json.entrySet().iterator();

            // Type check
            while (iter.hasNext()) {
                Entry<?, ?> entry = (Entry<?, ?>) iter.next();
                if (!(entry.getKey() instanceof String)) {
                    throw new IllegalArgumentException("Not in <String, Object> format");
                }
            }

            map = (Map<String, Object>) json;
        } catch (ParseException e) {
            e.printStackTrace();
            return;
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return;
        }
        if (map.containsKey("password-policy")) {
            // It will be a <String, Object>
            Map<String, Object> pw = (Map<String, Object>) map.get("password-policy");
            String method = (String) pw.get("method");
            // It will be a <String, Object>
            Map<String, Object> saltOpts = (Map<String, Object>) pw.get("salt");
            String salt = (String) saltOpts.get("salt");
            String format = (String) saltOpts.get("format");
            super.generatePasswordPolicy(PasswordPolicy.Method.getMethod(method), salt, format);
        }
        if (map.containsKey("time")) {
            Object time = map.get("time");
            if (time instanceof Double) {
                long t = ((Double) time).longValue();
                super.connectionTime.reportedTime = t;
                super.connectionTime.requestedTime = System.currentTimeMillis() / 1000;
            }
        }
    }
    if (super.getPasswordPolicy() != null) {
        String testHash = super.getPasswordPolicy().hashPassword("test-xmail-password");
        if (testHash == null) {
            super.generatePasswordPolicy(Method.SHA1, "", "P"); // Default
        }
    } else {
        super.generatePasswordPolicy(Method.SHA1, "", "P"); // Default
    }
}

From source file:de.tudarmstadt.lt.lm.lucenebased.CountingStringLM.java

public long getQuantity(List<String> ngram) {
    if (ngram == null)
        throw new IllegalAccessError("Ngram is null.");
    if (ngram.isEmpty())
        return 0L;
    String ngram_str = StringUtils.join(ngram, ' ');
    Term query_term = new Term("ngram", ngram_str);
    Query query = new TermQuery(query_term);
    try {// w  ww.ja  va2s.co  m
        Document doc = null;
        ScoreDoc[] hits = _searcher_ngram.search(query, 2).scoreDocs;
        if (hits.length >= 1) {
            if (hits.length > 1)
                LOG.warn("Found more than one entry for '{}', expected only one.", ngram_str);
            doc = _searcher_ngram.doc(hits[0].doc);
            return getQuantity(doc);
        }
    } catch (IOException e) {
        LOG.error("Could not get ngram {}. Luceneindex failed.", ngram_str, e);
    }
    return 0L;
}

From source file:fr.ens.biologie.genomique.eoulsan.Main.java

/**
 * Main method of the program./*from w ww.  j  a va2s .  co m*/
 * @param args command line arguments
 */
public static void main(final String[] args) {

    if (main != null) {
        throw new IllegalAccessError("Main method cannot be run twice.");
    }

    // Set the default local for all the application
    Globals.setDefaultLocale();

    // Check Java version
    if (getJavaVersion() < MINIMAL_JAVA_VERSION_REQUIRED) {
        Common.showErrorMessageAndExit(Globals.WELCOME_MSG + "\nError: " + Globals.APP_NAME + " requires Java "
                + MINIMAL_JAVA_VERSION_REQUIRED + ".");
    }

    // Select the application execution mode
    final String eoulsanMode = System.getProperty(Globals.LAUNCH_MODE_PROPERTY);

    if (eoulsanMode != null && eoulsanMode.equals("local")) {
        main = new MainCLI(args);
    } else {
        main = new MainHadoop(args);
    }

    // Get the action to execute
    final Action action = main.getAction();

    // Get the Eoulsan settings
    final Settings settings = EoulsanRuntime.getSettings();

    // Test if action can be executed with current platform
    if (!settings.isBypassPlatformChecking() && !action.isCurrentArchCompatible()) {
        Common.showErrorMessageAndExit(Globals.WELCOME_MSG + "\nError: The " + action.getName() + " of "
                + Globals.APP_NAME + " is not available for your platform. Required platforms: "
                + availableArchsToString() + ".");

    }

    try {

        getLogger().info("Start " + action.getName() + " action");

        // Run action
        action.action(main.getActionArgs());

        getLogger().info("End of " + action.getName() + " action");

    } catch (Throwable e) {
        Common.errorExit(e, e.getMessage());
    }

    // Flush logs
    main.flushLog();
}

From source file:com.baidu.cc.web.rpc.ConfigServerServiceImpl.java

/**
 * ???key?? ???? IllegalAccessError./* ww w.j a v a2  s . com*/
 * 
 * @param user
 *            ??
 * @param password
 *            ?
 * @param version
 *            ?
 * @param key
 *            key
 * @return ?
 */
@Override
public String getConfigItemValue(String user, String password, Long version, String key) {
    User u = authenticate(user, password);

    Version v = versionService.findById(version);
    if (v == null) {
        throw new IllegalAccessError("No version id '" + version + "' found. ");
    }
    authorizeProject(u, v.getProjectId());

    ConfigItem item = configItemService.findByVersionIdAndName(version, key, true);
    if (item == null) {
        return null;
    }

    return item.getVal();
}

From source file:madkitgroupextension.export.Export.java

public void process() throws Exception {
    //Runtime runtime=Runtime.getRuntime();
    File export_directory_tmp = new File(ExportPathTmp);
    if (export_directory_tmp.exists())
        FileTools.deleteDirectory(export_directory_tmp);
    //export_directory_tmp=new File(ExportPathTmp);
    export_directory_tmp.mkdir();/*from   w  ww  . java  2  s  . co m*/
    File exportroot = new File(ExportPathFinal);
    if (!exportroot.exists())
        exportroot.mkdir();
    File exportfinal = getExportFinal();
    if (!exportfinal.exists()) {
        File parent = exportfinal.getParentFile();
        if (!parent.exists())
            parent.mkdir();
        exportfinal.mkdir();
    }

    /*
     * creating the jar file
     */
    File jardirectory = new File(ExportPathTmp + "jardir/");
    jardirectory.mkdir();
    File jardirectorymkge = new File(ExportPathTmp + "jardir/madkitgroupextension/");
    jardirectorymkge.mkdir();

    File mkgedir = new File("bin/madkitgroupextension/");
    if (!mkgedir.exists())
        throw new IllegalAccessError("The MKGE directory does not exists !");
    if (!mkgedir.isDirectory())
        throw new IllegalAccessError("The directory bin/madkitgroupextension sould not be a file !");

    FileTools.copyFolderToFolder(mkgedir.getAbsolutePath(), "", mkgedir.getAbsolutePath(),
            jardirectorymkge.getAbsolutePath());

    if (m_export_source) {
        File mkgedirsrc = new File("src/madkitgroupextension/");
        if (!mkgedirsrc.exists())
            throw new IllegalAccessError("The MKGE source directory does not exists !");
        if (!mkgedirsrc.isDirectory())
            throw new IllegalAccessError("The directory src/madkitgroupextension sould not be a file !");

        FileTools.copyFolderToFolder(mkgedirsrc.getAbsolutePath(), "", mkgedirsrc.getAbsolutePath(),
                jardirectorymkge.getAbsolutePath());
    }
    File exportdir = new File(ExportPathTmp + "jardir/madkitgroupextension/export/");
    if (!exportdir.exists())
        throw new IllegalAccessError("The path " + exportdir.getAbsolutePath() + " should exist !");
    FileTools.deleteDirectory(exportdir);

    if (m_include_madkit) {
        File madkitdir = new File(ExportPathTmp + "madkit/");
        madkitdir.mkdir();

        //runtime.exec("unzip "+m_madkit_jar_file.getAbsoluteFile()+" -d "+madkitdir.getAbsolutePath());
        FileTools.unzipFile(m_madkit_jar_file, madkitdir);

        if (m_export_source) {
            File madkitsrc = new File(MadKitPath + "docs/madkit-" + m_madkit_version + "-src.zip");
            if (!madkitsrc.exists())
                throw new IllegalAccessError("The source of MadKit was not found !");

            //runtime.exec("unzip "+madkitsrc.getAbsoluteFile()+" -d "+madkitdir.getAbsolutePath());
            FileTools.unzipFile(madkitsrc, madkitdir);
        }

        FileTools.copyFolderToFolder(madkitdir.getAbsolutePath(), "", madkitdir.getAbsolutePath(),
                jardirectory.getAbsolutePath());
    }

    File metainf = new File(ExportPathTmp + "jardir/META-INF/");
    if (!metainf.exists())
        metainf.mkdir();
    //saveIndexList(new File(metainf, "INDEX.LIST"), new File(ExportPathTmp+"madkit/META-INF/INDEX.LIST"));

    createManifestFile(new File(ExportPathTmp + "jardir/META-INF/MANIFEST.MF"));
    createVersionFile(new File(jardirectory, "version.html"));
    createBuildFile(new File(jardirectory, "madkitgroupextension/kernel/build.txt"));

    File jarfile = new File(export_directory_tmp, getJarFileName());
    FileTools.zipDirectory(jardirectory, false, jarfile);
    //runtime.exec("zip "+jarfile.getAbsoluteFile()+" -r "+jardirectory.getAbsolutePath()+"/").waitFor();

    /*
     * Constructing the ZIP file containing the jar file and the documentation
     */

    if (!m_export_only_jar_file) {
        //generating java doc
        File srcforjavadoc = new File(ExportPathTmp + "srcforjavadoc/");
        srcforjavadoc.mkdir();
        File javadocdirectory = new File(ExportPathTmp + "javadocdir/");
        javadocdirectory.mkdir();

        File mkgedirsrc = new File("src/madkitgroupextension/");
        if (!mkgedirsrc.exists())
            throw new IllegalAccessError("The MKGE source directory does not exists !");
        if (!mkgedirsrc.isDirectory())
            throw new IllegalAccessError("The directory src/madkitgroupextension sould not be a file !");

        File mkgedirdst = new File(srcforjavadoc, "madkitgroupextension");
        mkgedirdst.mkdir();
        FileTools.copyFolderToFolder(mkgedirsrc.getAbsolutePath(), "", mkgedirsrc.getAbsolutePath(),
                mkgedirdst.getAbsolutePath());
        FileTools.deleteDirectory(new File(srcforjavadoc, "madkitgroupextension/export"));

        File madkitsrc = new File(MadKitPath + "docs/madkit-" + m_madkit_version + "-src.zip");
        if (!madkitsrc.exists())
            throw new IllegalAccessError("The source of MadKit was not found !");

        FileTools.unzipFile(madkitsrc, srcforjavadoc);

        String command = "javadoc -protected -link http://docs.oracle.com/javase/7/docs/api/ -sourcepath "
                + srcforjavadoc.getAbsolutePath() + " -d " + javadocdirectory.getAbsolutePath()
                + " -version -author -subpackages madkitgroupextension "
                + (m_include_madkit ? "-subpackages madkit" : "");
        System.out.println("\n*************************\n\n" + "Generating documentation\n"
                + "\n*************************\n\n");
        execExternalProcess(command, true, true);

        File zipdir = new File(export_directory_tmp, "zipdir");
        zipdir.mkdir();

        //File docsrcdir=new File("doc/");
        File docdstdir = new File(zipdir, "doc");
        docdstdir.mkdir();

        FileTools.copy(new File("COPYING").getAbsolutePath(), (new File(zipdir, "COPYING")).getAbsolutePath());
        FileTools.copy(jarfile.getAbsolutePath(), new File(zipdir, getJarFileName()).getAbsolutePath());

        createVersionFile(new File(zipdir, "MKGE_version.html"));

        FileTools.copyFolderToFolder(javadocdirectory.getAbsolutePath(), "", javadocdirectory.getAbsolutePath(),
                docdstdir.getAbsolutePath());

        if (m_include_madkit) {
            File madkitdocsrc = new File(MadKitPath, "docs");
            File madkitdocdst = new File(zipdir, "docsMadKit");
            madkitdocdst.mkdir();
            FileTools.copyFolderToFolder(madkitdocsrc.getAbsolutePath(), "", madkitdocsrc.getAbsolutePath(),
                    madkitdocdst.getAbsolutePath());

            FileTools.copy(new File(MadKitPath + "README.html").getAbsolutePath(),
                    (new File(zipdir, "MadKitReadMe.html")).getAbsolutePath());
            FileTools.deleteDirectory(new File(madkitdocdst, "api"));
            (new File(madkitdocdst, "src.zip")).delete();

            if (this.m_export_source) {
                File useddocdir = new File("./doc");
                if (useddocdir.exists()) {
                    if (useddocdir.isFile())
                        useddocdir.delete();
                    else
                        FileTools.deleteDirectory(useddocdir);
                }
                useddocdir.mkdir();
                FileTools.copyFolderToFolder(docdstdir.getAbsolutePath(), "", docdstdir.getAbsolutePath(),
                        useddocdir.getAbsolutePath());
                createVersionFile(new File(useddocdir, "MKGE_version.html"));
            }

        }
        //System.out.println("zip "+new File(exportfinal, getZipFileName()).getAbsoluteFile()+" -r "+zipdir.getAbsolutePath());
        FileTools.zipDirectory(zipdir, false, new File(exportfinal, getZipFileName()));
        //runtime.exec("zip "+new File(exportfinal, getZipFileName()).getAbsoluteFile()+" -r "+zipdir.getAbsolutePath());
    } else {
        FileTools.move(jarfile.getAbsolutePath(), new File(exportfinal, jarfile.getName()).getAbsolutePath());
    }

    //saveAndIncrementBuild();
    FileTools.deleteDirectory(export_directory_tmp);

}

From source file:org.onecmdb.utils.internal.nmap.NmapSystemDiscoverBeanProvider.java

public void run() throws Throwable {
    ISession session = (ISession) data.get("session");
    if (session == null) {
        throw new IllegalStateException("No 'session' found!");
    }//  w  w  w. j av a2s.  co  m

    IModelService modelService = (IModelService) session.getService(IModelService.class);

    // Validate input.
    validateTemplateExists(modelService, "hostnameTemplate", this.hostnameTemplate);
    validateTemplateExists(modelService, "ipTemplate", this.ipTemplate);
    validateTemplateExists(modelService, "dnsEntryTemplate", this.dnsEntryTemplate);
    validateTemplateExists(modelService, "netIfTemplate", this.netIfTemplate);
    validateTemplateExists(modelService, "nicTemplate", this.nicTemplate);

    // Run nmap.
    updateProgress("Running nmap");
    nmap = new RunToolProcess();
    nmap.setProgramPath(this.nmapExecutable);

    File output = File.createTempFile("NmapDiscover", ".xml");
    List<CiBean> discoverBeans = null;
    // Validate against current onecmdb.
    OneCmdbBeanProvider remoteBeanProvider = new OneCmdbBeanProvider();
    remoteBeanProvider.setModelService(modelService);

    try {
        String outputPath = output.getCanonicalPath();
        updateProgressPercentage(5);
        List<String> args = new ArrayList<String>();
        args.add("-sP");
        args.add(getTarget());
        args.add("-oX");
        args.add(outputPath);

        nmap.setArguments(args);

        nmapIsRunning = true;

        nmap.run();

        nmapIsRunning = false;

        updateProgress("nmap ended");

        updateProgressPercentage(40);

        if (nmap.getOutParameter().get("ok").equals("false")) {
            String cause = (String) nmap.getOutParameter().get("cause");
            throw new IllegalStateException("Problem running nmap : " + cause);
        }

        String inputFile = outputPath;

        TransformNmap transformNmap = new TransformNmap();
        transformNmap.setNicTemplate(nicTemplate);
        transformNmap.setIpTemplate(ipTemplate);
        transformNmap.setHostnameTemplate(hostnameTemplate);
        transformNmap.setNetIfTemplate(netIfTemplate);
        transformNmap.setDnsEntryTemplate(dnsEntryTemplate);

        transformNmap.setBeanProvider(remoteBeanProvider);

        transformNmap.setInput(inputFile);
        discoverBeans = transformNmap.transform();

        updateProgressPercentage(50);

    } finally {
        // Cleanup temp file.
        if (output != null) {
            boolean deleted = output.delete();
            if (!deleted) {
                log.warn("Temporary nmap output file '" + output.getAbsolutePath() + "' can not be deleted");
            }
        }
    }

    CiBean ipContainerBean = null;
    if (this.ipContainer != null) {
        ipContainerBean = new CiBean();
        ipContainerBean.setAlias(this.ipContainer.getAlias());
        ipContainerBean.setDerivedFrom(this.ipContainer.getDerivedFrom().getAlias());
        ipContainerBean.setTemplate(false);
        this.beanMap.put(ipContainerBean.getAlias(), ipContainerBean);
        this.beans.add(ipContainerBean);
    }

    CiBean nicContainerBean = null;
    if (this.nicContainer != null) {
        nicContainerBean = new CiBean();
        nicContainerBean.setAlias(this.nicContainer.getAlias());
        nicContainerBean.setDerivedFrom(this.nicContainer.getDerivedFrom().getAlias());
        nicContainerBean.setTemplate(false);
        this.beanMap.put(nicContainerBean.getAlias(), nicContainerBean);
        this.beans.add(nicContainerBean);
    }
    CiBean hostnameContainerBean = null;
    if (hostnameContainer != null) {
        hostnameContainerBean = new CiBean();
        hostnameContainerBean.setAlias(this.hostnameContainer.getAlias());
        hostnameContainerBean.setDerivedFrom(this.hostnameContainer.getDerivedFrom().getAlias());
        hostnameContainerBean.setTemplate(false);
        this.beanMap.put(hostnameContainerBean.getAlias(), hostnameContainerBean);
        this.beans.add(hostnameContainerBean);
    }

    CiBean dnsEntryContainerBean = null;

    if (this.dnsEntryContainer != null) {
        dnsEntryContainerBean = new CiBean();
        dnsEntryContainerBean.setAlias(this.dnsEntryContainer.getAlias());
        dnsEntryContainerBean.setDerivedFrom(this.dnsEntryContainer.getDerivedFrom().getAlias());
        dnsEntryContainerBean.setTemplate(false);
        this.beanMap.put(dnsEntryContainerBean.getAlias(), dnsEntryContainerBean);
        this.beans.add(dnsEntryContainerBean);
    }

    CiBean netIfContainerBean = null;
    if (netIfContainer != null) {
        netIfContainerBean = new CiBean();
        netIfContainerBean.setAlias(this.netIfContainer.getAlias());
        netIfContainerBean.setDerivedFrom(this.netIfContainer.getDerivedFrom().getAlias());
        netIfContainerBean.setTemplate(false);
        this.beanMap.put(netIfContainerBean.getAlias(), netIfContainerBean);
        this.beans.add(netIfContainerBean);
    }

    updateProgressPercentage(60);

    for (CiBean bean : discoverBeans) {
        if (terminated) {
            throw new IllegalStateException("Discover system was stopped");
        }

        this.beanMap.put(bean.getAlias(), bean);
        this.beans.add(bean);

        // add it to the correct foled also.
        if (bean.getDerivedFrom().equals(this.hostnameTemplate)) {
            if (hostnameContainerBean != null) {
                hostnameContainerBean.addAttributeValue(new ValueBean("hostnames", bean.getAlias(), true));
            }
        } else if (bean.getDerivedFrom().equals(this.ipTemplate)) {
            if (ipContainerBean != null) {
                ipContainerBean.addAttributeValue(new ValueBean("ips", bean.getAlias(), true));
            }
        } else if (bean.getDerivedFrom().equals(this.nicTemplate)) {
            if (nicContainerBean != null) {
                nicContainerBean.addAttributeValue(new ValueBean("nics", bean.getAlias(), true));
            }
        } else if (bean.getDerivedFrom().equals(this.netIfTemplate)) {
            if (netIfContainerBean != null) {
                netIfContainerBean.addAttributeValue(new ValueBean("networkInterfaces", bean.getAlias(), true));
            }
        } else if (bean.getDerivedFrom().equals(this.dnsEntryTemplate)) {
            if (dnsEntryContainerBean != null) {
                dnsEntryContainerBean.addAttributeValue(new ValueBean("dnsEntries", bean.getAlias(), true));
            }
        }
    }

    updateProgressPercentage(65);
    // Process beans
    ProcessBeanProvider importBeans = new ProcessBeanProvider();
    WorkflowParameter par = new WorkflowParameter();
    par.put("provider", this);
    par.put("validation", "false");
    importBeans.setInParameter(par);
    importBeans.setRelevantData(data);
    importBeans.run();

    updateProgressPercentage(80);

    // Commit
    BeanScope scope = (BeanScope) importBeans.getOutParameter().get("scope");
    List<IRFC> rfcs = scope.getRFCs();

    CommitRfcProcess commit = new CommitRfcProcess();
    WorkflowParameter par1 = new WorkflowParameter();
    System.out.println(rfcs.size() + " Rfc's generated ");
    par1.put("rfcs", rfcs);
    commit.setInParameter(par1);
    commit.setRelevantData(data);
    commit.run();

    updateProgressPercentage(100);

    String ok = (String) commit.getOutParameter().get("ok");
    String cause = (String) commit.getOutParameter().get("cause");

    if (!ok.equals("true")) {
        throw new IllegalAccessError("Can't commit changes:" + cause);
    }
    return;
}

From source file:org.sakaiproject.component.common.edu.person.SakaiPersonManagerImpl.java

/**
 * @see SakaiPersonManager#save(SakaiPerson)
 *///  w ww  .j av a2 s . co m
public void save(SakaiPerson sakaiPerson) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("save(SakaiPerson " + sakaiPerson + ")");
    }
    if (sakaiPerson == null)
        throw new IllegalArgumentException("Illegal sakaiPerson argument passed!");
    if (!isSupportedType(sakaiPerson.getTypeUuid()))
        throw new IllegalArgumentException("The sakaiPerson argument contains an invalid Type!");

    // AuthZ
    // Only superusers can update system records
    if (getSystemMutableType().getUuid().equals(sakaiPerson.getTypeUuid()) && !SecurityService.isSuperUser()) {
        throw new IllegalAccessError("System mutable records cannot be updated.");
    }

    // if it is a user mutable record, ensure the user is updating their own record
    // this can be overriden with a security advisor so the admin user to allow access
    if (!SecurityService.unlock(UserDirectoryService.ADMIN_ID, SakaiPerson.PROFILE_SAVE_PERMISSION,
            sakaiPerson.getAgentUuid())) {

        if (!StringUtils.equals(SessionManager.getCurrentSessionUserId(), sakaiPerson.getAgentUuid())
                && !SecurityService.isSuperUser()) {
            // AuthZ - Ensure the current user is updating their own record
            if (!StringUtils.equals(SessionManager.getCurrentSessionUserId(), sakaiPerson.getAgentUuid())) {
                throw new IllegalAccessError("You do not have permissions to update this record!");
            }
        }
    }

    // store record
    if (!(sakaiPerson instanceof SakaiPersonImpl)) {
        // TODO support alternate implementations of SakaiPerson
        // copy bean properties into new SakaiPersonImpl with beanutils?
        throw new UnsupportedOperationException("Unknown SakaiPerson implementation found!");
    } else {
        // update lastModifiedDate
        SakaiPersonImpl spi = (SakaiPersonImpl) sakaiPerson;
        persistableHelper.modifyPersistableFields(spi);
        //if the repository path is set save if there
        if (photoService.overRidesDefault()) {
            photoService.savePhoto(spi.getJpegPhoto(), spi.getAgentUuid());
            spi.setJpegPhoto(null);
        }

        // use update(..) method to ensure someone does not try to insert a
        // prototype.
        getHibernateTemplate().update(spi);

        //set the event
        String ref = getReference(spi);
        LOG.debug("got ref of: " + ref + " about to set events");

        eventTrackingService.post(eventTrackingService.newEvent("profile.update", ref, true));

        LOG.debug("User record updated for Id :-" + spi.getAgentUuid());
        //update the account too -only if not system profile 
        if (serverConfigurationService.getBoolean("profile.updateUser", false)
                && spi.getTypeUuid().equals(this.userMutableType.getUuid())) {
            try {
                UserEdit userEdit = null;
                userEdit = userDirectoryService.editUser(spi.getAgentUuid());
                userEdit.setFirstName(spi.getGivenName());
                userEdit.setLastName(spi.getSurname());
                userEdit.setEmail(spi.getMail());
                userDirectoryService.commitEdit(userEdit);
                LOG.debug("Saved user object");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}