
org.efaps.ui.wicket.models.AbstractInstanceObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of efaps-webapp Show documentation
Show all versions of efaps-webapp Show documentation
eFaps WebApp provides a web interface as the User Interface for eFaps
which can be easily expanded and altered.
/*
* Copyright 2003 - 2009 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: 3754 $
* Last Changed: $Date: 2010-02-19 21:27:21 -0500 (Fri, 19 Feb 2010) $
* Last Changed By: $Author: jan.moxter $
*/
package org.efaps.ui.wicket.models;
import java.util.HashMap;
import java.util.Map;
import org.apache.wicket.IClusterable;
import org.apache.wicket.RequestCycle;
import org.efaps.db.Instance;
import org.efaps.ui.wicket.EFapsWebRequestCycle;
import org.efaps.ui.wicket.util.EFapsKey;
import org.efaps.util.EFapsException;
/**
* TODO comment!
*
* @author The eFaps Team
* @version $Id: AbstractInstanceObject.java 3447 2009-11-29 22:46:39Z
* tim.moxter $
*/
public abstract class AbstractInstanceObject
implements IClusterable
{
/**
* Needed for serialization.
*/
private static final long serialVersionUID = 1L;
/**
* key to the instance.
*/
private String instanceKey;
public AbstractInstanceObject()
{
}
public AbstractInstanceObject(final String _instanceKey)
{
this.instanceKey = _instanceKey;
}
/**
* Getter method for instance variable {@link #instanceKey}.
*
* @return value of instance variable {@link #instanceKey}
*/
public String getInstanceKey()
{
return this.instanceKey;
}
/**
* @see org.efaps.ui.wicket.models.AbstractInstanceObject#getInstance()
* @return Instance of the object
* @throws EFapsException on error
*/
@SuppressWarnings("unchecked")
public Instance getInstance()
throws EFapsException
{
Instance ret = null;
Map map;
final EFapsWebRequestCycle cycle = (EFapsWebRequestCycle) RequestCycle.get();
map = (Map) cycle.getFromCache(EFapsKey.INSTANCE_CACHEKEY.getKey());
if (map == null) {
map = new HashMap();
cycle.putIntoCache(EFapsKey.INSTANCE_CACHEKEY.getKey(), map);
}
if (map.containsKey(this.instanceKey)) {
ret = map.get(this.instanceKey);
} else {
if (hasInstanceManager()) {
ret = getInstanceFromManager();
} else if ((this.instanceKey != null)
&& (this.instanceKey.length() > 0)) {
ret = Instance.get(getInstanceKey());
}
map.put(this.instanceKey, ret);
}
return ret;
}
/**
* Setter method for instance variable {@link #instanceKey}.
*
* @param _instanceKey value for instance variable {@link #instanceKey}
*/
public void setInstanceKey(final String _instanceKey)
{
this.instanceKey = _instanceKey;
}
public abstract Instance getInstanceFromManager()
throws EFapsException;
public abstract boolean hasInstanceManager();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy