org.efaps.update.schema.program.JavaUpdate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of efaps-kernel Show documentation
Show all versions of efaps-kernel Show documentation
eFaps is a framework used to map objects with or without attached files to
a relational database and optional file systems (only for attaches files). Configurable access control can be provided down to object and attribute level depending on implementation and use case. Depending on requirements, events (like triggers) allow to implement business logic and to separate business logic from user interface.
The framework includes integrations (e.g. webdav, full text search) and a web application as 'simple' configurable user interface. Some best practises, example web application modules (e.g. team work module) support administrators and implementers using this framework.
/*
* Copyright 2003 - 2011 The eFaps Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Revision: $Rev: 6210 $
* Last Changed: $Date: 2011-02-18 16:02:56 -0500 (Fri, 18 Feb 2011) $
* Last Changed By: $Author: [email protected] $
*/
package org.efaps.update.schema.program;
import java.net.URL;
import java.util.Set;
import org.efaps.update.AbstractUpdate;
import org.efaps.update.UpdateLifecycle;
import org.efaps.update.schema.program.esjp.ESJPImporter;
import org.efaps.update.util.InstallationException;
/**
* Handles the import / update of ESJP's (eFaps stored Java Programs) for eFaps
* read from a plain Java source code file.
*
* @author The eFaps Team
* @version $Id: JavaUpdate.java 6210 2011-02-18 21:02:56Z [email protected] $
*/
public class JavaUpdate
extends AbstractSourceUpdate
{
/**
* Default constructor to initialize this ESJP update instance for given
* _url
.
*
* @param _url url to the file
*/
public JavaUpdate(final URL _url)
{
super(_url, "Admin_Program_Java");
}
/**
* If the extension of the file is .java
, the method returns
* an instance of this class. The instance of this class owns one definition
* instance where the code and the name is defined.
*
* @param _url URL of the file depending of the root URL
* @return Java update definition read by digester
*/
public static JavaUpdate readFile(final URL _url)
{
final JavaUpdate ret = new JavaUpdate(_url);
final JavaDefinition definition = ret.new JavaDefinition(_url);
ret.addDefinition(definition);
return ret;
}
/**
* The Java definition holds the code and the name of the Java class.
*/
public class JavaDefinition
extends SourceDefinition
{
/**
* Importer for the ESJP.
*/
private ESJPImporter javaCode = null;
/**
* @param _url URL to the java file
*/
protected JavaDefinition(final URL _url)
{
super(_url);
}
/**
* Search the instance.
*
* @throws InstallationException if the Java source code could not be
* read or the file could not be accessed
* because of the wrong URL
*/
@Override
protected void searchInstance()
throws InstallationException
{
if (this.javaCode == null) {
this.javaCode = new ESJPImporter(getUrl());
}
setName(this.javaCode.getProgramName());
if (this.javaCode.getEFapsUUID() != null) {
addValue("UUID", this.javaCode.getEFapsUUID().toString());
}
if (this.javaCode.getRevision() != null) {
addValue("Revision", this.javaCode.getRevision());
}
if (this.instance == null) {
this.instance = this.javaCode.searchInstance();
}
}
/**
* The method overwrites the method from the super class, because a
* check in of the Java source code is needed after the update in the
* database.
*
* @param _step current update step
* @param _allLinkTypes all link types to update
* @throws InstallationException on error
*/
@Override
public void updateInDB(final UpdateLifecycle _step,
final Set _allLinkTypes)
throws InstallationException
{
if (_step == UpdateLifecycle.EFAPS_UPDATE) {
if (AbstractUpdate.LOG.isInfoEnabled() && (this.javaCode.getProgramName() != null)) {
AbstractUpdate.LOG.info(" Update " + this.instance.getType().getName() + " '"
+ this.javaCode.getProgramName() + "'");
}
this.javaCode.updateDB(this.instance);
} else {
super.updateInDB(_step, _allLinkTypes);
}
}
/**
* {@inheritDoc}
*/
@Override
protected String getRevision()
throws InstallationException
{
if (this.javaCode == null) {
this.javaCode = new ESJPImporter(getUrl());
}
return this.javaCode.getRevision();
}
}
}