Methods Summary |
---|
public void | addConfigContextEventListener(com.sun.enterprise.config.ConfigContextEventListener ccel)
if (listeners==null)
listeners = new Vector();
listeners.addElement(ccel);
|
public synchronized com.sun.enterprise.config.ConfigChange | addToConfigChangeList(java.lang.String parentXpath, java.lang.String childXpath, java.lang.String name, com.sun.enterprise.config.ConfigBean cb)for add
//adds
if(!isAdministered) return null;
ConfigChange cChange = ConfigChangeFactory.createConfigAdd
(parentXpath, childXpath, name, cb);
configChangeList.add(cChange);
persistConfigChanges();
return cChange;
|
public synchronized com.sun.enterprise.config.ConfigChange | addToConfigChangeList(java.lang.String xpath)
if(!isAdministered) return null;
ConfigChange cChange = null;
if(!removeOtherConfigChanges(xpath)) {
cChange = ConfigChangeFactory.createConfigDelete(xpath);
configChangeList.add(cChange);
}
persistConfigChanges();
return cChange;
|
public synchronized com.sun.enterprise.config.ConfigChange | addToConfigChangeList(java.lang.String parentXpath, java.lang.String name, java.lang.Object cb, java.lang.Object[] cbArray)
if(!isAdministered) return null;
ConfigChange cChange = ConfigChangeFactory.createConfigSet(
parentXpath,
name,
cb,
cbArray);
configChangeList.add(cChange);
persistConfigChanges();
return cChange;
|
public synchronized com.sun.enterprise.config.ConfigChange | addToConfigChangeList(java.lang.String xpath, java.lang.String attrName, java.lang.String oldValue, java.lang.String newValue)
//find xpath and add. else create new obj.
if(!isAdministered) return null;
ConfigChange cChange = null;
try {
if(oldValue == null && newValue == null) return null;
if(oldValue != null && oldValue.equals(newValue)) return null;
boolean found = false;
for(int i=0;i<configChangeList.size();i++) {
if(((ConfigChange)configChangeList.get(i)).getConfigChangeType().equals(ConfigChange.TYPE_UPDATE)
&& ((ConfigUpdate)configChangeList.get(i)).getXPath().equals(xpath)) {
((ConfigUpdate)configChangeList.get(i)).addChangedAttribute(attrName, oldValue, newValue);
//_logger.log(Level.INFO,"config.change_added");
persistConfigChanges();
found = true;
break;
}
}
if(!found) {
cChange = ConfigChangeFactory.createConfigUpdate
(xpath,
attrName,
oldValue,
newValue);
configChangeList.add(cChange);
persistConfigChanges();
//_logger.log(Level.INFO,"config.create_config_ch_obj",xpath);
}
} catch (Throwable t) {
//_logger.log(Level.WARNING,"config.add_config_change_exception",t);
}
return cChange;
|
private void | assertReadOnly()
if(readOnly) {
throw new ConfigException("Read only: you cannot write " + toString() );
}
|
private void | change(java.lang.String when, com.sun.enterprise.config.ConfigContextEvent ne)
if (listeners==null)
return;
//ConfigContextEvent ne = new ConfigContextEvent(this, type);
String type = ne.getType();
Vector listenersClone = null;
synchronized (listeners) {
listenersClone = (Vector) listeners.clone();
}
for (Enumeration e = listenersClone.elements(); e.hasMoreElements();) {
ConfigContextEventListener nl = (ConfigContextEventListener) e.nextElement();
if(when.equals(PRE_CHANGE)) {
/*
if(type.equals(ConfigContextEvent.PRE_ACCESS) || type.equals(ConfigContextEvent.POST_ACCESS))
nl.preAccessNotification(ne);
else
*/
nl.preChangeNotification(ne);
} else {
/*
if(type.equals(ConfigContextEvent.PRE_ACCESS) || type.equals(ConfigContextEvent.POST_ACCESS))
nl.postAccessNotification(ne);
else
*/
nl.postChangeNotification(ne);
}
}
|
public void | cleanup()recursive method that cleansup the config context and allows better memory model
This should be called when we know that the tree in this context is used in future
//set ctx and xpath
//_logger.fine("Cleaning up config context");
if(server != null)
cleanup(server);
//_logger.fine("Finished setting xpath for the whole tree");
server = null;
|
private void | cleanup(com.sun.enterprise.config.ConfigBean cb)
cb.cleanup();
//_logger.finer(" " + cb.name() + " cleaned up");
//if cb is leaf. return.
ConfigBean[] chChildArr = cb.getAllChildBeans();
if(chChildArr == null || chChildArr.length <= 0) return;
for(int i = 0; i<chChildArr.length; i++) {
if(chChildArr[i] == null) continue;
//_logger.finest("Child " + chChildArr[i].name());
try {
cleanup(chChildArr[i]);
} catch(Throwable t) {
//ignore this node and its children and continue with rest
//_logger.fine("Warning: Cannot cleanup configbean " + chChildArr[i].name());
//_logger.fine("Warning: Exception is: " + t.getMessage());
//_logger.fine("Warning: Continuing with rest of settings");
}
}
|
private void | clearPersistentConfigChanges()
if(!LOAD_PERSISTENT_CONFIG_CHANGES) return;
//remove change file on disk
try {
File f = new File(getConfigChangeUrl());
f.delete();
} catch(Throwable t) {
//ignore.
}
|
public java.lang.Object | clone()
ConfigContextImpl ctxClone =
new ConfigContextImpl(this.xmlUrl, false, false, this.rootClass, this.defaultHandler);
ctxClone.configBeanInterceptor = getConfigBeanInterceptor();
/*
server is initialized on refresh(). What if someone calls clone()
before server is initialized.
*/
if (server != null) {
ConfigBean rootClone = (ConfigBean)this.server.clone();
ctxClone.setRootConfigBean(rootClone);
rootClone.setConfigContext(ctxClone);
rootClone.setInterceptor(ctxClone.configBeanInterceptor);
try {
((ConfigContextImpl)ctxClone).setXPathInAllBeans();
} catch (Exception e) {
//ignore
}
}
ctxClone.setIsAdministered(true);
return ctxClone;
|
public java.lang.String | configBeanToString()get the ConfigBean information as a String
String is in a schema2beans proprietory format
Note that this method is not exposed in ConfigContext.
if(server == null) return "null bean";
return this.server.dumpBeanNode();
|
public synchronized boolean | enableLastModifiedCheck(boolean value)This method is used to activate the lastModified checking for a configContext
If activated, configbeans will carry a lastmodified timestamp in every bean.
This time is also carried onto the configChangeList and also to clones. When
configContext.updateFromConfigChangeList is called, the timestamp is first checked
to see if the bean has not changed since the clone and then the update is made.
If a modification to the bean is detected, a staleWriteConfigException is thrown.
boolean prev = _lastModifiedCheck;
_lastModifiedCheck = value;
return prev;
|
public boolean | equals(java.lang.Object obj)
try {
if(this.getRootConfigBean().equals(((ConfigContext)obj).getRootConfigBean())) {
return true;
}
} catch(Throwable t) {
//ignore
}
return false;
|
public com.sun.enterprise.config.ConfigBean | exactLookup(java.lang.String xpath)Retrieves the named object. The parameter passed is a
XPath version 1.0
used as the path notation for navigating the hierarchical structure. Only the AbsoluteLocationPath
and Relative LocationPath elements are used.
The code below returns a ConfigBeam representing an application with appId="app1"
ConfigBean cn = conCtx.exactLookup(ServerXPathHelper.getAppIdXpathExpression("app1"));
if(server == null) {
refresh();
}
return ConfigBeansFactory.getConfigBeanByXPath(this,xpath);
|
public synchronized void | flush(boolean overwrite)saves all the changes in ConfigContext to storage
Throws ConfigException if there is any problem writing to storage.
or the file has been modified after last read.
However, if overwrite is true, then it overwrites any manual changes
on disk
if(!overwrite && isFileChangedExternally()) {
throw new StaleWriteConfigException
("ConfigContext Flush failed: File Changed Externally");
}
// <addition> srini@sun.com server.xml verifier
//preChange(ConfigContextEvent.PRE_FLUSH_CHANGE);
ConfigContextEvent ccce = new ConfigContextEvent(this,ConfigContextEvent.PRE_FLUSH_CHANGE);
preChange(ccce);
// </addition> server.xml verifier
try {
FileOutputStream fos = new FileOutputStream(this.xmlUrl);
server.write(fos);
} catch(Exception e) {
throw new ConfigException("Error Flushing ConfigContext " + toString());
}
initLastModified();
// <addition> srini@sun.com
//postChange(ConfigContextEvent.POST_FLUSH_CHANGE);
ccce = new ConfigContextEvent(this,ConfigContextEvent.POST_FLUSH_CHANGE);
postChange(ccce);
// </addition> server.xml verifier
//FIXME: should I not write out persistentConfigChanges now??
|
public void | flush()is equivalent to flush(true)
flush(true);
|
public java.lang.String | getAttributeValue(java.lang.String xpath, java.lang.String attributeName)Get the Value of an attribute with One call
This equivalent of doing an exactLookup to get a bean
and then a getAttributeValue on that bean
ConfigBean c = null;
try {
c = this.exactLookup(xpath);
} catch(Exception e) {}
if(c!= null) {
if(!isResolvingPaths()) {
return c.getRawAttributeValue(attributeName);
} else {
return c.getAttributeValue(attributeName);
}
}
return null;
|
public boolean | getBooleanAttributeValue(java.lang.String xpath, java.lang.String attributeName)similar to getAttributeValue but returns a boolean
String ret = getAttributeValue(xpath, attributeName);
if(ret == null) return false;
if (ret.equals("true"))
return true;
return false;
|
private com.sun.enterprise.config.ConfigBean | getConfigBeanFromConfigChange(com.sun.enterprise.config.ConfigChange configChange)
ConfigBean result = null;
try {
if(configChange.getConfigChangeType().equals(ConfigChange.TYPE_UPDATE)) {
result = ConfigBeansFactory.getConfigBeanByXPath(this,configChange.getXPath());
} else if (configChange.getConfigChangeType().equals(ConfigChange.TYPE_DELETE)) {
String xpath = configChange.getXPath();
ConfigBean child = ConfigBeansFactory.getConfigBeanByXPath(this,xpath);
if(child != null) {
result = (ConfigBean) child.parent();
}
} else { // add/set
result = ConfigBeansFactory.getConfigBeanByXPath(this, configChange.getParentXPath());
}
} catch (ConfigException ce) {
//ignore
}
return result;
|
public com.sun.enterprise.config.pluggable.ConfigBeanInterceptor | getConfigBeanInterceptor()
ConfigBeanInterceptor cbiClone = null;
if (null != configBeanInterceptor) {
cbiClone = (ConfigBeanInterceptor)configBeanInterceptor.clone();
}
return cbiClone;
|
public java.util.ArrayList | getConfigChangeList()
return configChangeList;
|
private java.lang.String | getConfigChangeUrl()
return this.xmlUrl + ".changes";
|
private long | getLastModified()
long ts = INVALID_LAST_MODIFIED;
try {
File f = new File(this.xmlUrl);
ts = f.lastModified();
} catch(Exception e) {
//ignore
}
return ts;
|
public synchronized com.sun.enterprise.config.ConfigBean | getRootConfigBean()
if(server == null) {
refresh();
}
return server;
|
public java.lang.String | getUrl()
return this.xmlUrl;
|
java.lang.String | getXmlUrl()
return this.xmlUrl;
|
public int | hashCode()
try {
return this.getRootConfigBean().hashCode();
} catch(Throwable t) {
//ignore
}
return super.hashCode();
|
private void | initConfigChanges()
if(!LOAD_PERSISTENT_CONFIG_CHANGES) return;
FileInputStream istream = null;
try {
istream = new FileInputStream(getConfigChangeUrl());
ObjectInputStream p = new ObjectInputStream(istream);
this.configChangeList = (ArrayList)p.readObject();
} catch(Throwable t) {
//ignore.
} finally {
try {
istream.close();
} catch(Exception e){}
}
|
private void | initLastModified()init to be called from constructor
this.lastModified = getLastModified();
|
public boolean | isAdministered()
return isAdministered;
|
public boolean | isChanged()
if(configChangeList == null || configChangeList.size() ==0)
return false;
return true;
|
public boolean | isFileChangedExternally()checks if file has changed externally after the config context
last updated the file
if(getLastModified() == this.lastModified)
return false;
return true;
|
public boolean | isLastModifiedCheckEnabled()
return _lastModifiedCheck;
|
public boolean | isResolvingPaths()Returns boolean true is this is the config context for admin.
return this.resolvePath;
|
public com.sun.enterprise.config.ConfigBean[] | lookup(java.lang.String xpath)
// FIXME NYI
return null;
|
private void | persistConfigChanges()
//We donot need to write if persistent
//config changes are not required
if(!LOAD_PERSISTENT_CONFIG_CHANGES) return;
FileOutputStream ostream = null;
ObjectOutputStream p = null;
try {
ostream = new FileOutputStream(getConfigChangeUrl());
p = new ObjectOutputStream(ostream);
p.writeObject(this.configChangeList);
p.flush();
} catch(Throwable t) {
//ignore.
} finally {
try {
p.close();
ostream.close();
} catch(Exception e){}
}
|
public void | postChange(com.sun.enterprise.config.ConfigContextEvent ccce)
//change(POST_CHANGE, type);
change(POST_CHANGE, ccce);
|
public void | preChange(com.sun.enterprise.config.ConfigContextEvent ccce)Notify all my listeners that I will change!
// <addition> srini@sun.com server.xml verifier
//public void preChange(String type) {
//change(PRE_CHANGE, type);
change(PRE_CHANGE, ccce);
|
public synchronized void | refresh(boolean force)discards all the changes and reloads the xml from storage based on the force flag
try {
if(!force && isChanged()) {
throw new ConfigException
("ConfigContext has changed in Memory. cannot refresh " + toString());
}
FileInputStream in = new FileInputStream(this.xmlUrl);
if(this.defaultHandler != null) {
server = (ConfigBean) BaseBean.createGraph(
rootClass,
in,
true,
this.defaultHandler,
this.defaultHandler);
} else {
server = (ConfigBean) BaseBean.createGraph(rootClass, in, true);
}
initConfigChanges(); // not reset. load it up.
initLastModified();
//setXpath for the tree of readwrite mode
if(INITIALIZE_XPATH) {
if(!this.readOnly) {
setXPathInAllBeans();
}
}
setIsAdministered(true);
server.setInterceptor(this.configBeanInterceptor);
} catch (Exception e) {
throw new ConfigException("Error refreshing ConfigContext:" + this.xmlUrl, e);
}
|
public void | refresh()discards all the changes and reloads the xml from storage if dirty flag is true
refresh(true);
|
public synchronized void | removeConfigChange(com.sun.enterprise.config.ConfigChange change)
if (!isAdministered) return;
int ndx = configChangeList.indexOf(change);
if (ndx != -1) {
configChangeList.remove(ndx);
}
persistConfigChanges();
|
public void | removeConfigContextEventListener(com.sun.enterprise.config.ConfigContextEventListener ccel)
if (listeners==null)
listeners = new Vector();
listeners.removeElement(ccel);
|
private boolean | removeOtherConfigChanges(java.lang.String xpath)
boolean ret = false;
try {
//Bug# 4884726 Begin
final Iterator it = configChangeList.iterator();
while (it.hasNext()) {
final ConfigChange cc = (ConfigChange)it.next();
if(xpath.indexOf(cc.getXPath()) >= 0) {
if(cc instanceof ConfigAdd)
ret = true;
it.remove();
}
}
//Bug# 4884726 End
} catch (Throwable t) {
//_logger.log(Level.WARNING,"config.remove_config_change_exception",t);
}
return ret;
|
public synchronized void | resetConfigChangeList()
configChangeList = new ArrayList();
clearPersistentConfigChanges();
//FIXME
isAdministered = true;
|
public void | setIsAdministered(boolean value)
isAdministered = value;
|
void | setRootConfigBean(com.sun.enterprise.config.ConfigBean c)
this.server = c;
|
public void | setXPathInAllBeans()sets xpath in all beans
if(this.readOnly) return;
ConfigBean cb = this.getRootConfigBean();
//set ctx and xpath
//_logger.fine("Setting xpath for the whole tree");
setXPathInTree(cb,"");
//_logger.fine("Finished setting xpath for the whole tree");
|
private void | setXPathInTree(com.sun.enterprise.config.ConfigBean cb, java.lang.String parentXpath)recursive method
cb.setConfigContext(this);
String xp = cb.getAbsoluteXPath(parentXpath);
//_logger.finer(" " + cb.name() + " " + xp);
cb.setXPath(xp);
//if cb is leaf. return.
ConfigBean[] chChildArr = cb.getAllChildBeans();
if(chChildArr == null || chChildArr.length <= 0) return;
for(int i = 0; i<chChildArr.length; i++) {
if(chChildArr[i] == null) continue;
//_logger.finest("Child " + chChildArr[i].name());
try {
setXPathInTree(chChildArr[i], cb.getXPath());
} catch(Throwable t) {
//ignore this node and its children and continue with rest
//_logger.fine("Error: Cannot setXpath for " + chChildArr[i].name());
//_logger.fine("Error: Xpath is " + cb.getXPath());
//_logger.fine("Error: Exception is: " + t.getMessage());
//_logger.fine("Error: Continuing with rest of settings");
}
}
|
public java.lang.String | toString()get all the important attributes of this configcontext as a String
Each attribute is separated by a comma
return "com.sun.enterprise.config.ConfigContext: Url=" + this.xmlUrl
+ ", ReadOnly=" + this.readOnly
+ ", ResolvePath=" + (resolvePath)
+ ", LastModified Timestamp=" + this.lastModified
+ ", isChanged=" + this.isChanged()
+ ", Autocommit=" + this.autoCommit
+ ", isConfigBeanNull=" + (server==null);
|
private void | updateFromConfigAdd(com.sun.enterprise.config.ConfigAdd configChange)
ConfigBean parent = ConfigBeansFactory.getConfigBeanByXPath(this,configChange.getParentXPath());
if(parent == null)
throw new ConfigException("updateFromConfigAdd: Cannot find parent");
ConfigBean rootBean = configChange.getConfigBean();
if(rootBean == null)
throw new ConfigException("updateFromConfigAdd: Cannot find root bean");
ConfigBean childBean = ConfigBeansFactory.getConfigBeanByXPath(rootBean, configChange.getXPath());
if(childBean == null)
throw new ConfigException("updateFromConfigAdd: Cannot find childBean");
//lastModified Check
if(isLastModifiedCheckEnabled()) {
validateLastModified(parent, configChange);
}
childBean = (ConfigBean)childBean.clone();
//System.out.println("++++++++++before add +++++++++++++++");
//System.out.println("this childBean:");
//System.out.println(childBean.dumpBeanNode());
//System.out.println("++++++++++++++++++++++++++++++++");
//System.out.println(childBean.dumpDomNode());
//System.out.println("++++++++++before add +++++++++++++++");
parent.addValue(configChange.getName(), childBean);
//System.out.println("++++++++++after add +++++++++++++++");
//System.out.println("this configcontxt:");
//this.getRootConfigBean().dumpXml();
//System.out.println("++++++++++after add +++++++++++++++");
|
public synchronized void | updateFromConfigChange(com.sun.enterprise.config.ConfigChange configChange)
if(configChange == null) return;
//disable configChangeList while updating.
//otherwise, we get unnecessary changes in the list.
boolean tmpAdministered = isAdministered;
isAdministered = false;
if(configChange.getConfigChangeType().equals(ConfigChange.TYPE_ADD))
updateFromConfigAdd((ConfigAdd)configChange);
else if(configChange.getConfigChangeType().equals(ConfigChange.TYPE_UPDATE))
updateFromConfigUpdate((ConfigUpdate)configChange);
else if(configChange.getConfigChangeType().equals(ConfigChange.TYPE_DELETE))
updateFromConfigDelete((ConfigDelete)configChange);
else if(configChange.getConfigChangeType().equals(ConfigChange.TYPE_SET))
updateFromConfigSet((ConfigSet)configChange);
//enable if needed.
isAdministered = tmpAdministered;
|
public synchronized java.util.ArrayList | updateFromConfigChange(java.util.ArrayList configChangeList)
ArrayList errList = new ArrayList();
if (configChangeList == null || configChangeList.size() == 0) return errList;
validateAllLastModified(configChangeList);
boolean prev = enableLastModifiedCheck(false);
try {
for(int i = 0 ; i < configChangeList.size(); i++ ) {
ConfigChange cc = (ConfigChange) configChangeList.get(i);
try {
updateFromConfigChange(cc);
} catch (Exception e) {
errList.add(cc);
}
}
// save the context. TBD
} finally {
enableLastModifiedCheck(prev);
}
return errList;
|
private void | updateFromConfigDelete(com.sun.enterprise.config.ConfigDelete configChange)
//delete
String xpath = configChange.getXPath();
ConfigBean child = ConfigBeansFactory.getConfigBeanByXPath(this,xpath);
if(child != null) {
//throw new ConfigException("Child not found:" + xpath);
ConfigBean parent = (ConfigBean) child.parent();
//lastModified Check
if(isLastModifiedCheckEnabled()) {
validateLastModified(parent, configChange);
}
parent.removeChild(child);
}
|
private void | updateFromConfigSet(com.sun.enterprise.config.ConfigSet configChange)
ConfigBean parent = ConfigBeansFactory.getConfigBeanByXPath(this,configChange.getParentXPath());
if(parent == null)
throw new ConfigException("updateFromConfigSet: Cannot update. Could not get parent");
Object child = configChange.getConfigBean();
//lastModified Check
if(isLastModifiedCheckEnabled()) {
validateLastModified(parent, configChange);
}
if(child != null) {
parent.setValue(configChange.getName(), child);
} else { //it is an array
Object[] childArray = configChange.getConfigBeanArray();
parent.setValue(configChange.getName(), childArray);
}
|
private void | updateFromConfigUpdate(com.sun.enterprise.config.ConfigUpdate configChange)
//set all the attributes
//System.out.println("configchange is:" + configChange);
//System.out.println("++++++++++++++++++++++++++++");
//System.out.println("this configcontext:" + this);
//System.out.println("++++++++++++++++++++++++++++");
ConfigBean b = ConfigBeansFactory.getConfigBeanByXPath(this,configChange.getXPath());
//_logger.log(Level.FINE,"xpath="+ configChange.getXPath());
if(b == null)
throw new ConfigException("updateFromConfigUpdate:Could not find ConfigBean to update");
//lastModified Check
if(isLastModifiedCheckEnabled()) {
validateLastModified(b, configChange);
}
Set s = configChange.getAttributeSet();
for (Iterator i = s.iterator();i.hasNext();) {
String name = (String) i.next();
b.setAttributeValue(name, configChange.getNewValue(name));
}
|
private void | validateAllLastModified(java.util.ArrayList arr)
if(arr == null || arr.size() == 0) return;
for(int i = 0 ; i < arr.size(); i++ ) {
ConfigChange cc = (ConfigChange) arr.get(i);
validateLastModified(cc);
}
|
private void | validateLastModified(com.sun.enterprise.config.ConfigBean cb, com.sun.enterprise.config.ConfigChange cc)throws StaleWriteConfigException if lastmodified is initialized
and there is any modifications
if(cb == null || cc == null) return;
long beanLM = cb.getThisLastModified();
if(beanLM == -1) return; // not initialized. so, don't validate
long ccLM = cc.getGlobalLastModified();
if(ccLM == -1) return; // not initialized. so, don't validate
if (beanLM == ccLM) return; // okay.
throw new StaleWriteConfigException("validateLastModified failed for cb=" + cb);
|
private void | validateLastModified(com.sun.enterprise.config.ConfigChange cc)
ConfigBean bean = getConfigBeanFromConfigChange(cc);
validateLastModified(bean, cc);
|