]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.client.ui.dist/src/org/argeo/slc/client/ui/dist/model/ModularDistVersionBaseElem.java
Add cglib back
[gpl/argeo-slc.git] / org.argeo.slc.client.ui.dist / src / org / argeo / slc / client / ui / dist / model / ModularDistVersionBaseElem.java
1 package org.argeo.slc.client.ui.dist.model;
2
3 import javax.jcr.Node;
4 import javax.jcr.NodeIterator;
5 import javax.jcr.RepositoryException;
6 import javax.jcr.query.QueryManager;
7 import javax.jcr.query.QueryResult;
8 import javax.jcr.query.qom.Constraint;
9 import javax.jcr.query.qom.QueryObjectModel;
10 import javax.jcr.query.qom.QueryObjectModelFactory;
11 import javax.jcr.query.qom.Selector;
12
13 import org.argeo.ArgeoException;
14 import org.argeo.slc.SlcException;
15 import org.argeo.slc.jcr.SlcNames;
16 import org.argeo.slc.jcr.SlcTypes;
17
18 /**
19 * Abstract the base of a given modular distribution set i.e. the parent of all
20 * versions of a given modular distribution
21 */
22 public class ModularDistVersionBaseElem extends DistParentElem {
23
24 // final static public String AETHER_CATEGORY_BASE = "categoryBase";
25 final static public String AETHER_BINARIES_TYPE = "binaries";
26 final static public String AETHER_DEP_TYPE = "dep";
27 private String type;
28 private Node modularDistVersionBase;
29
30 public ModularDistVersionBaseElem(WorkspaceElem wkspElem, String name,
31 Node modularDistVersionBase, String type) {
32 super(name, wkspElem.inHome(), wkspElem.isReadOnly());
33 setParent(wkspElem);
34 this.modularDistVersionBase = modularDistVersionBase;
35 this.type = type;
36 }
37
38 public Node getModularDistBase() {
39 // // TODO clean this
40 // if (type.equals(AETHER_CATEGORY_BASE))
41 // return modularDistVersionBase;
42 // else
43 try {
44 return modularDistVersionBase.getParent();
45 } catch (RepositoryException e) {
46 throw new SlcException("unable to get parent node for "
47 + modularDistVersionBase, e);
48 }
49 }
50
51 public WorkspaceElem getWkspElem() {
52 return (WorkspaceElem) getParent();
53 }
54
55 /**
56 * Override normal behaviour to initialise children only when first
57 * requested
58 */
59 @Override
60 public synchronized boolean hasChildren() {
61 if (isLoaded()) {
62 return super.hasChildren();
63 } else {
64 return true;
65 }
66 };
67
68 /**
69 * Override normal behaviour to initialise children only when first
70 * requested
71 */
72 @Override
73 public synchronized Object[] getChildren() {
74 if (isLoaded()) {
75 return super.getChildren();
76 } else {
77 try {
78 NodeIterator ni = getDistVersions();
79 while (ni != null && ni.hasNext()) {
80 Node curNode = ni.nextNode();
81 if (curNode.hasProperty(SlcNames.SLC_ARTIFACT_VERSION))
82 addChild(new ModularDistVersionElem(this, curNode
83 .getProperty(SlcNames.SLC_ARTIFACT_VERSION)
84 .getString(), curNode));
85 }
86 return super.getChildren();
87 } catch (RepositoryException re) {
88 throw new ArgeoException("Unable to retrieve children for "
89 + modularDistVersionBase, re);
90 }
91 }
92 }
93
94 private NodeIterator getDistVersions() {
95 try {
96 // if (AETHER_CATEGORY_BASE.equals(type))
97 // return null;
98
99 QueryManager queryManager = modularDistVersionBase.getSession()
100 .getWorkspace().getQueryManager();
101 QueryObjectModelFactory factory = queryManager.getQOMFactory();
102 Selector source = factory.selector(
103 SlcTypes.SLC_MODULAR_DISTRIBUTION,
104 SlcTypes.SLC_MODULAR_DISTRIBUTION);
105 Constraint constraint = factory.descendantNode(
106 source.getSelectorName(), modularDistVersionBase.getPath());
107 // Ordering order = factory.descending(factory.propertyValue(
108 // source.getSelectorName(), SlcNames.SLC_ARTIFACT_VERSION));
109 // Ordering[] orderings = { order };
110 QueryObjectModel query = factory.createQuery(source, constraint,
111 null, null);
112 QueryResult queryResult = query.execute();
113 return queryResult.getNodes();
114 } catch (RepositoryException e) {
115 throw new SlcException(
116 "Unable to version for modular distribution: " + getName(),
117 e);
118 }
119 }
120
121 public String getType() {
122 return type;
123 }
124 }