com.viaoa.hub.HubFlattened Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oa-core Show documentation
Show all versions of oa-core Show documentation
Object Automation library
The newest version!
/* Copyright 1999 Vince Via [email protected]
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.
*/
package com.viaoa.hub;
import com.viaoa.hub.HubListener.InsertLocation;
import com.viaoa.object.OALinkInfo;
import com.viaoa.object.OAObject;
import com.viaoa.object.OAObjectInfo;
/**
* Takes a recursive hub (hubRoot) and populates a Hub (hubFlat) with all of the children.
*/
public class HubFlattened {
private Hub hubRoot;
private Hub hubFlat;
// private OALinkInfo liToRoot;
private OALinkInfo liRecursiveToParent;
private HubMerger hm;
public HubFlattened(Hub hubRoot, Hub hubFlat) {
this.hubRoot = hubRoot;
this.hubFlat = hubFlat;
setup();
}
public Hub getRootHub() {
return hubRoot;
}
@Override
protected void finalize() throws Throwable {
super.finalize();
hm.close();
}
void setup() {
if (hubFlat == null || hubRoot == null) {
return;
}
// must be recursive
OAObjectInfo oi = hubRoot.getOAObjectInfo();
liRecursiveToParent = oi.getRecursiveLinkInfo(OALinkInfo.ONE);
if (liRecursiveToParent == null) {
throw new RuntimeException(hubRoot + " is not recursive");
}
// property that owns hubRoot
// liToRoot = HubDetailDelegate.getLinkInfoFromDetailToMaster(hubRoot);
hm = new HubMerger(hubRoot, hubFlat, liRecursiveToParent.getReverseName(), false, null, true, true, true);
// make sure that any new object added to hubFlat(from a new command) has correct link to parent/master
HubListener hl = new HubListenerAdapter() {
@Override
public void afterInsert(HubEvent e) {
afterAdd(e);
}
@Override
public void afterAdd(HubEvent e) {
if (e == null) {
return;
}
if (liRecursiveToParent == null) {
return;
}
if (liRecursiveToParent.getValue(e.getObject()) != null) {
return;
}
hubRoot.add((TYPE) e.getObject()); // this will set it
}
};
hl.setLocation(InsertLocation.LAST);
hubFlat.addHubListener(hl);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy