Added:
trunk/procilege/src/main/java/procilege/impl/PrivilegeFormReaction.java
Modified:
trunk/procilege/pom.xml
trunk/procilege/src/main/java/procilege/impl/ComputationalEntityMgr.java
trunk/procilege/src/test/java/procilege/test/pal/AbstractPalTest.java
trunk/procilege/src/test/java/procilege/test/pal/ComputationalEntityMgrTest1.java
Log:
[Issue 34]Reaction of privilege form; changed the dependency for ANTLR-3.0.
Modified: trunk/procilege/pom.xml
==============================================================================
--- trunk/procilege/pom.xml (original)
+++ trunk/procilege/pom.xml Sun Jun 10 11:30:54 2007
@@ -26,7 +26,7 @@
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
- <version>3.0b6</version>
+ <version>3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -82,7 +82,7 @@
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr</artifactId>
- <version>3.0b6</version>
+ <version>3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Modified: trunk/procilege/src/main/java/procilege/impl/ComputationalEntityMgr.java
==============================================================================
--- trunk/procilege/src/main/java/procilege/impl/ComputationalEntityMgr.java (original)
+++ trunk/procilege/src/main/java/procilege/impl/ComputationalEntityMgr.java Sun Jun 10 11:30:54 2007
@@ -7,14 +7,10 @@
import javax.xml.namespace.QName;
import merisis.MerisisVM;
-import merisis.contentcloud.ContentCloud;
import merisis.sense.SenseMaker;
-import merisis.traitspace.AmbiguityException;
+import merisis.traitspace.EntityHappen;
import merisis.traitspace.Morphism;
-import merisis.util.BitUtil;
-
import procilege.compiler.PalCompiler;
-import procilege.compute.ExprFormatter;
import procilege.lang.Name;
import procilege.lang.PrivExprElement;
import procilege.lang.PrivilegeForm;
@@ -35,12 +31,6 @@
private SenseMaker smr;
@Inject
- private ContentCloud cloud;
-
- @Inject
- private ExprFormatter ftr;
-
- @Inject
private MerisisVM mvm;
@Inject
@@ -52,6 +42,9 @@
@Inject
private Morphism mp;
+ @Inject
+ private EntityHappen eh;
+
private long namePalLiteral = 0;
private long namePrivExpr = 0;
@@ -112,7 +105,15 @@
if (initial)
init();
- updateExpr(((NameImpl)name).nameId, namePrivExpr, expr);
+ mvm.give(((NameImpl) name).nameId);
+ mvm.stepin();
+ try {
+ long[] ontos = new long[1];
+ ontos[0] = namePrivExpr;
+ eh.happen(ontos, expr);
+ } finally {
+ mvm.stepout();
+ }
}
public PrivExprElement retrievePrivlegeExpr(Name name) {
@@ -120,21 +121,22 @@
if (initial)
init();
- // threadfocus.zoomin(m(((NameImpl) name).nameId));
- // try {
- // long[] list = focusExprInstances(namePrivExpr);
- // if (list == null)
- // return null;
- //
- // if (list.length > 1)
- // throw new IllegalStateException("Not Focused!!!");
- //
- // return cloud.retrieve(list[0]);
- //
- // } finally {
- // threadfocus.leave();
- // }
- return null;
+ Object value;
+
+ mvm.give(((NameImpl) name).nameId);
+ mvm.stepin();
+ try {
+ value = eh.retrieve(new long[] { namePrivExpr });
+ } finally {
+ mvm.stepout();
+ }
+
+ if (value instanceof PrivExprElement) {
+ return (PrivExprElement) value;
+ } else {
+ logger.warning("invalid type: " + value);
+ return null;
+ }
}
public PrivilegeForm retrievePrivlegeForm(Name name) {
@@ -142,130 +144,63 @@
if (initial)
init();
- long nameid = ((NameImpl) name).nameId;
-
- // threadfocus.zoomin(m(nameid));
- // try {
- // TraitGraph tgh;
- // tgh = ts.analyze(threadfocus.get(), c(namePrivExpr));
- // HistoricalHierarchy hh = tgh.historical();
- // tgh = ts.analyze(threadfocus.get(), c(nameNormalForm));
- // hh.exclude(tgh.historical());
- // long[] list = hh.roll(0);
- // if (list != null) {
- //
- // // the normal form is stale!
- // if (logger.isLoggable(Level.FINER)) {
- //
- // StringBuilder sb = new StringBuilder();
- // sb.append("Empty or Stale of the normal form: ");
- // BitUtil.format(sb, list, ",");
- // logger.finer(sb.toString());
- // }
- // if (list.length > 1) {
- //
- // StringBuilder sb = new StringBuilder();
- // sb.append("no focused:");
- // BitUtil.format(sb, list, ",");
- //
- // throw new IllegalStateException(sb.toString());
- // }
- // return updatePrivNormalForm(name, list[0]);
- // }
- // tgh = ts.analyze(threadfocus.get(), c(nameNormalForm));
- // hh = tgh.historical();
- // list = hh.roll(0);
- // if (list == null) {
- // logger.warning("NO found the privilege: " + ftr.toString(name));
- // return null;
- // }
- //
- // if (list.length > 1)
- // throw new AmbiguityException(list);
- //
- // return cloud.retrieve(list[0]);
- //
- // } finally {
- // threadfocus.leave();
- // }
- return null;
- }
-
- /**
- * STRUCTURE: ((entity, property, meta_entity_prop), value)
- */
- public void setEntityProperty(Name entity, String property, Object value) {
-
if (initial)
init();
- long subject = ((NameImpl) entity).nameId;
- long predicate = smr.sense(new QName(PROPS_NS, property));
-
- mvm.give(subject, predicate, namePropEntities);
- mvm.source();
- mvm.focus();
- long[] onto = mvm.read();
-
- long occurence = -1;
- if (onto == null || onto.length == 0) {
-
- occurence = mvm.occur(subject, predicate, namePropEntities);
- } else if (onto.length == 1) {
+ Object value;
- occurence = onto[0];
- } else if (onto.length > 0) {
-
- occurence = mvm.occur(onto);
+ mvm.give(((NameImpl) name).nameId);
+ mvm.stepin();
+ try {
+ value = eh.retrieve(new long[] { nameNormalForm });
+ } finally {
+ mvm.stepout();
}
- long cid = cloud.occur(value);
- occurence = mvm.occur(occurence, cid);
-
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest(String.format(
- "<subject=%d, predicate=%d, value=%d>, "
- + "occurence: %d, onto:{%s}", subject, predicate,
- cid, occurence, BitUtil.toString(onto)));
+ if (value instanceof PrivilegeForm) {
+ return (PrivilegeForm) value;
+ } else {
+ logger.warning("invalid type: " + value);
+ return null;
}
}
- public Object getEntityProperty(Name entity, String property) {
+ public void setEntityProperty(Name entity, String property, Object value) {
if (initial)
init();
- long subject = ((NameImpl) entity).nameId;
- long predicate = smr.sense(new QName(PROPS_NS, property));
-
- long[] onto;
- mvm.give(subject, predicate, namePropEntities);
+ mvm.give(((NameImpl) entity).nameId);
mvm.stepin();
try {
- mvm.focus();
- onto = mvm.read();
+ long[] ontos = new long[2];
+ ontos[0] = smr.sense(new QName(PROPS_NS, property));
+ ontos[1] = namePropEntities;
+ eh.happen(ontos, value);
} finally {
mvm.stepout();
}
+ }
+
+ public Object getEntityProperty(Name entity, String property) {
+
+ if (initial)
+ init();
- mvm.autobeam();
+ Object value;
+
+ mvm.give(((NameImpl) entity).nameId);
+ mvm.stepin();
try {
- // NOTICE: changes the souces instead of the focus.
- mvm.give(subject, predicate, namePropEntities);
- mvm.tprism();
- mvm.tcomplementary();
- onto = mvm.read();
+ long[] ontos = new long[2];
+ ontos[0] = smr.sense(new QName(PROPS_NS, property));
+ ontos[1] = namePropEntities;
+ value = eh.retrieve(ontos);
} finally {
mvm.stepout();
}
- if (onto == null || onto.length == 0)
- return null;
-
- if (onto.length > 1)
- throw new AmbiguityException(null);
-
- return cloud.retrieve(onto[0]);
+ return value;
}
public void setIsA(Name subject, Name object) {
@@ -288,67 +223,4 @@
return mp.exists(nameIsA, sid, oid);
}
-
- private PrivilegeFormImpl updatePrivNormalForm(Name name, long pv) {
-
- PrivilegeFormImpl pf = new PrivilegeFormImpl(name);
- pf.expr = retrievePrivlegeExpr(name);
- pf.isDirty = true;
-
- // threadfocus.zoomin(m(pv));
- // try {
- // updateExpr(name, nameNormalForm, pf);
- // } finally {
- // threadfocus.leave();
- // }
-
- return pf;
- }
-
- /**
- * STRUCTURE: ((subject, onto), value)
- */
- private void updateExpr(long subject, long ontotype, Object value) {
-
- mvm.give(subject, ontotype);
- mvm.source();
- mvm.focus();
- long[] r = mvm.read();
-
- long occ1 = -1;
- if (r == null || r.length == 0) {
-
- occ1 = mvm.occur(subject, ontotype);
- } else if (r.length == 1) {
-
- occ1 = r[0];
- } else if (r.length > 0) {
-
- throw new AmbiguityException(r);
- }
-
- long cid = cloud.occur(value);
- long occ2 = mvm.occur(occ1, cid);
-
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest(String.format(
- "((subject:%d, onto:%d):%d, value:%d):%d", subject,
- ontotype, cid, occ1, occ2));
- }
- }
-
- private long[] focusExprInstances(long upperconstruct) {
-
- // TraitGraph tgh;
- // tgh = ts.analyze(threadfocus.get(), m(upperconstruct));
- // HistoricalHierarchy hh = tgh.historical();
- // long[] list = hh.roll(0);
- // if (list == null)
- // return null;
- // tgh = ts.analyze(threadfocus.get(), c(list));
- // hh = tgh.historical();
- //
- // return hh.roll(0);
- return null;
- }
-}
+}
\ No newline at end of file
Added: trunk/procilege/src/main/java/procilege/impl/PrivilegeFormReaction.java
==============================================================================
--- (empty file)
+++ trunk/procilege/src/main/java/procilege/impl/PrivilegeFormReaction.java Sun Jun 10 11:30:54 2007
@@ -0,0 +1,51 @@
+package procilege.impl;
+
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import merisis.contentcloud.ContentCloud;
+import merisis.sense.SenseMaker;
+import merisis.traitspace.EntityHappen;
+import merisis.traitspace.HappenReaction;
+import procilege.lang.PrivExprElement;
+
+import com.google.inject.Inject;
+
+public class PrivilegeFormReaction implements HappenReaction {
+
+ @Inject
+ private Logger logger;
+
+ @Inject
+ private EntityHappen eh;
+
+ @Inject
+ private ContentCloud cloud;
+
+ @Inject
+ private SenseMaker smr;
+
+ public void happen(long[] points) {
+
+ long metaNormalForm = smr.sense(new QName(
+ ComputationalEntityMgr.PAL_METAENTITY_NS,
+ ComputationalEntityMgr.PAL_PNORMAL_EXPR));
+
+ for (int i = 0; i < points.length; i++) {
+
+ long origplace = points[i];
+ Object content = cloud.retrieve(origplace);
+ if (content == null || !(content instanceof PrivExprElement)) {
+ logger.warning(String.format("illegal content: %s", content));
+ continue;
+ }
+
+ PrivilegeFormImpl pf = new PrivilegeFormImpl(new NameImpl(origplace));
+ pf.isDirty = true;
+ pf.expr = (PrivExprElement) content;
+
+ eh.happen(new long[] { metaNormalForm }, pf, origplace);
+ }
+ }
+}
Modified: trunk/procilege/src/test/java/procilege/test/pal/AbstractPalTest.java
==============================================================================
--- trunk/procilege/src/test/java/procilege/test/pal/AbstractPalTest.java (original)
+++ trunk/procilege/src/test/java/procilege/test/pal/AbstractPalTest.java Sun Jun 10 11:30:54 2007
@@ -108,6 +108,9 @@
guice.injectMembers(this);
}
+ /**
+ * Merge the elements of privilege expression.
+ */
protected PrivExprElement pvm(PrivExprElement... expr) {
if (expr == null)
Modified: trunk/procilege/src/test/java/procilege/test/pal/ComputationalEntityMgrTest1.java
==============================================================================
--- trunk/procilege/src/test/java/procilege/test/pal/ComputationalEntityMgrTest1.java (original)
+++ trunk/procilege/src/test/java/procilege/test/pal/ComputationalEntityMgrTest1.java Sun Jun 10 11:30:54 2007
@@ -34,9 +34,5 @@
def(nn("p1"), pvm(nn("d")));
dumpHistory(0, 30);
assertEquals(pvm(nn("d")), cem.retrievePrivlegeExpr(nn("p1")));
-
- // pf1 = cem.retrievePrivlegeForm(nn("p1"));
- // assertNotNull(pf1);
- // cem.updatePrivlegeExpr(, nn("p1"));
}
-}
+}
\ No newline at end of file