/** Resolves to nns associated with 'name' and set Continuation to the result. */ protected void resolve_to_nns_and_continue(Name name, Continuation cont) throws NamingException { if (debug > 0) System.out.println("RESOLVE TO NNS AND CONTINUE" + name.toString()); if (resolve_to_penultimate_context_nns(name, cont)) { Object nns = a_lookup_nns(name.toString(), cont); if (nns != null) cont.setContinue(nns, name, this); } }
@Override protected final Expr unLambda(final Name n) { final Map<Name, Expr> map = defs.unLambda().getMap(); final LinkedList<Set<Name>> sorted = topoSort(map); Expr ex = getBody(); for (final Set<Name> names : sorted) { if (names.size() == 1) { final Name nm = names.iterator().next(); final Expr def = map.get(nm); final int uses = ex.numOfUses(nm); if (uses == 0) { // name unused, ignore it log.info("removing unused definition " + nm + ": " + def); } else if (uses == 1 || def instanceof Value) { // can be inlined log.info("inlining " + nm + ": " + def); ex = ex.inline(nm, def); } else { ex = App.create(new Lambda(nm.toString(), ex), map.get(nm)); } } else { final Name[] na = names.toArray(new Name[names.size()]); Expr funs = NIL, res = K.app(ex); for (final Name element : na) { funs = CONS.app(map.get(element), funs); } funs = K.app(funs); for (final Name element : na) { funs = U.app(new Lambda(element.toString(), funs)); if (res.hasFree(element)) { res = U.app(new Lambda(element.toString(), res)); } else { // name unused, ignore it log.info("rewriting unused name: U { " + element + " -> f } ==> (f . tl)"); final Name nm = Name.createName(); res = new Lambda(nm.toString(), App.create(res, TL.app(nm))); } } ex = App.create(res, Y.app(funs)); } } return ex.unLambda(n); }
/** * Resolves to penultimate context named by 'name'. Returns true if penultimate context has been * reached (i.e. name only has one atomic component left). Returns false otherwise, and sets * Continuation to parts of name not yet resolved. */ protected boolean resolve_to_penultimate_context(Name name, Continuation cont) throws NamingException { String target = name.toString(); if (debug > 0) System.out.println("RESOLVE TO PENULTIMATE" + target); StringHeadTail ht = c_parseComponent(target, cont); String tail = ht.getTail(); String head = ht.getHead(); if (head == null) { // something is wrong; no name at all InvalidNameException e = new InvalidNameException(); throw cont.fillInException(e); } if (!isEmpty(tail)) { // more components; hence not at penultimate context yet try { Object headCtx = a_lookup(head, cont); if (headCtx != null) cont.setContinue(headCtx, head, this, tail); else if (cont.isContinue()) cont.appendRemainingComponent(tail); } catch (NamingException e) { e.appendRemainingComponent(tail); throw e; } } else { // already at penultimate context cont.setSuccess(); // clear return true; } return false; }
/** * Constructs a JNDI Binding object from the COS Naming binding object. * * @exception NameNotFound No objects under the name. * @exception CannotProceed Unable to obtain a continuation context * @exception InvalidName Name not understood. * @exception NamingException One of the above. */ private javax.naming.Binding mapBinding(org.omg.CosNaming.Binding bndg) throws NamingException { java.lang.Object obj = _ctx.callResolve(bndg.binding_name); Name cname = CNNameParser.cosNameToName(bndg.binding_name); try { obj = NamingManager.getObjectInstance(obj, cname, _ctx, _env); } catch (NamingException e) { throw e; } catch (Exception e) { NamingException ne = new NamingException("problem generating object using object factory"); ne.setRootCause(e); throw ne; } // Use cname.toString() instead of bindingName because the name // in the binding should be a composite name String cnameStr = cname.toString(); javax.naming.Binding jbndg = new javax.naming.Binding(cnameStr, obj); NameComponent[] comps = _ctx.makeFullName(bndg.binding_name); String fullName = CNNameParser.cosNameToInsString(comps); jbndg.setNameInNamespace(fullName); return jbndg; }
/** * Resolve to context named by 'name'. Returns true if at named context (i.e. 'name' is empty * name). Returns false otherwise, and sets Continuation on parts of 'name' not yet resolved. */ protected boolean resolve_to_context(Name name, Continuation cont) throws NamingException { String target = name.toString(); StringHeadTail ht = c_parseComponent(target, cont); String tail = ht.getTail(); String head = ht.getHead(); if (debug > 0) System.out.println("RESOLVE TO CONTEXT(" + target + ") = {" + head + ", " + tail + "}"); if (head == null) { // something is wrong; no name at all InvalidNameException e = new InvalidNameException(); throw cont.fillInException(e); } if (!isEmpty(head)) { // if there is head is a non-empty name // this means more resolution to be done try { Object headCtx = a_lookup(head, cont); // System.out.println("answer " + headCtx); if (headCtx != null) cont.setContinue(headCtx, head, this, (tail == null ? "" : tail)); else if (cont.isContinue()) cont.appendRemainingComponent(tail); } catch (NamingException e) { e.appendRemainingComponent(tail); throw e; } } else { cont.setSuccess(); // clear return true; } return false; }
/** Returns a recursively created XML representation of this <code>Meta</code>. */ public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append("<" + xmltag + ">" + newline); if (null != corpus_id) { buffer.append("\t\t\t" + corpus_id.toString()); } if (null != history) { buffer.append("\t\t\t" + history.toString()); } if (null != format) { buffer.append("\t\t\t" + format.toString()); } if (null != name) { buffer.append("\t\t\t" + name.toString()); } if (null != author) { buffer.append("\t\t\t" + author.toString()); } if (null != date) { buffer.append("\t\t\t" + date.toString()); } if (null != description) { buffer.append("\t\t\t" + description.toString()); } buffer.append("\t\t</" + xmltag + ">" + newline); return buffer.toString(); }
/** * Adds the components of a compound name -- in order -- at a specified position within this * compound name. Components of this compound name at or after the index of the first new * component are shifted up (away from index 0) to accommodate the new components. * * <p>Implementation note: Currently the syntax properties of suffix is not used or checked. They * might be in the future. * * @param n The non-null components to add. * @param posn The index in this name at which to add the new components. Must be in the range * [0,size()]. * @return The updated CompoundName, not a new one. Cannot be null. * @exception ArrayIndexOutOfBoundsException If posn is outside the specified range. * @exception InvalidNameException If n is not a compound name, or if the addition of the * components violates the syntax of this compound name (e.g. exceeding number of components). */ public Name addAll(int posn, Name n) throws InvalidNameException { if (n instanceof CompoundName) { impl.addAll(posn, n.getAll()); return this; } else { throw new InvalidNameException("Not a compound name: " + n.toString()); } }
public void rename(Name oldName, Name newName) throws NamingException { Object value = lookup(oldName); unbind(oldName); if (value instanceof ContextImpl) ((ContextImpl) value).setName(newName.toString()); bind(newName, value); }
/** * Adds the components of a compound name -- in order -- to the end of this compound name. * * <p>Implementation note: Currently the syntax properties of suffix is not used or checked. They * might be in the future. * * @param suffix The non-null components to add. * @return The updated CompoundName, not a new one. Cannot be null. * @exception InvalidNameException If suffix is not a compound name, or if the addition of the * components violates the syntax of this compound name (e.g. exceeding number of components). */ public Name addAll(Name suffix) throws InvalidNameException { if (suffix instanceof CompoundName) { impl.addAll(suffix.getAll()); return this; } else { throw new InvalidNameException("Not a compound name: " + suffix.toString()); } }
/** Returns the full name for the context. */ protected String getFullPath(Name name) { if (_name == null || _name.equals("")) return name.toString(); else if (name == null || name.size() == 0) return _name; String sep = getSeparatorString(); return _name + sep + name; }
protected void c_unbind_nns(Name name, Continuation cont) throws NamingException { if (_contextType == _ATOMIC) { if (resolve_to_penultimate_context_nns(name, cont)) a_unbind_nns(name.toString(), cont); } else { // use ComponentContext super.c_unbind_nns(name, cont); } }
protected Context c_createSubcontext_nns(Name name, Continuation cont) throws NamingException { if (_contextType == _ATOMIC) { if (resolve_to_penultimate_context_nns(name, cont)) return a_createSubcontext_nns(name.toString(), cont); else return null; } else { // use ComponentContext return super.c_createSubcontext_nns(name, cont); } }
protected Object c_lookup(Name name, Continuation cont) throws NamingException { Object ret = null; if (resolve_to_penultimate_context(name, cont)) { ret = a_lookup(name.toString(), cont); if (ret != null && ret instanceof LinkRef) { cont.setContinue(ret, name, this); ret = null; } } return ret; }
/** * @see Name * @see Substitution * <p>Unifying Method similar to Unify but with an important difference. If one of the * unifying names is smaller or bigger than the other, this method considers that the names * can still be partially unifyable. The regular Unify method will always return false in such * situations. * @param n1 - The first Name * @param n2 - The second Name * @param binding - Place an empty Substitution List here * @return True if the names are unifyable, even if they do not have the same size one can be * unified with the initial partof the other, in this case the bindings list will contain the * found Substitutions, otherwise it will be empty */ public static boolean PartialUnify(Name n1, Name n2, ArrayList<Substitution> bindings) { Name aux1; Name aux2; ArrayList<Substitution> bindAux; if (n1 == null || n2 == null) return false; // parto do principio que a lista de bindings está consistente aux1 = (Name) n1.clone(); aux2 = (Name) n2.clone(); aux1.makeGround(bindings); aux2.makeGround(bindings); if (aux1.isGrounded() && aux2.isGrounded()) { return aux1.toString().startsWith(aux2.toString()) || aux2.toString().startsWith(aux1.toString()); } bindAux = FindPartialSubst(aux1, aux2); if (bindAux == null) return false; bindings.addAll(bindAux); return true; }
protected Object c_lookup_nns(Name name, Continuation cont) throws NamingException { if (_contextType == _ATOMIC) { Object ret = null; if (resolve_to_penultimate_context_nns(name, cont)) { ret = a_lookup_nns(name.toString(), cont); if (ret != null && ret instanceof LinkRef) { cont.setContinue(ret, name, this); ret = null; } } return ret; } else { return super.c_lookup_nns(name, cont); } }
/** * This function is similar to resolve_to_penultimate_context() except it should only be called by * the nns() functions. This function fixes any exception or continuations so that it will have * the proper nns name. */ protected boolean resolve_to_penultimate_context_nns(Name name, Continuation cont) throws NamingException { try { if (debug > 0) System.out.println("RESOLVE TO PENULTIMATE NNS" + name.toString()); boolean answer = resolve_to_penultimate_context(name, cont); // resolve_to_penultimate_context() only calls a_lookup(). // Any continuation it sets is lacking the nns, so // we need to add it back if (cont.isContinue()) cont.appendRemainingComponent(""); return answer; } catch (NamingException e) { // resolve_to_penultimate_context() only calls a_lookup(). // Any exceptions it throws is lacking the nns, so // we need to add it back. e.appendRemainingComponent(""); throw e; } }
@Override public Name addAll(int index, Name name) throws InvalidNameException { if (name == null) { // jndi.00=name must not be null throw new NullPointerException(Messages.getString("jndi.00")); // $NON-NLS-1$ } if (!(name instanceof CompoundName)) { // jndi.09={0} is not a compound name. throw new InvalidNameException(Messages.getString("jndi.09", name.toString())); // $NON-NLS-1$ } if (FLAT.equals(direction) && (size() + name.size() > 1)) { // jndi.0A=A flat name can only have a single component throw new InvalidNameException(Messages.getString("jndi.0A")); // $NON-NLS-1$ } validateIndex(index, true); final Enumeration<String> enumeration = name.getAll(); while (enumeration.hasMoreElements()) { elems.add(index++, enumeration.nextElement()); } return this; }
protected void c_rename(Name oldname, Name newname, Continuation cont) throws NamingException { if (resolve_to_penultimate_context(oldname, cont)) a_rename(oldname.toString(), newname, cont); }
/** * Lists the contents of a context or subcontext. The operation is delegated to the serial * context. * * @return an enumeration of the contents of the context. * @throws NamingException if there is a naming exception. */ @Override public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { // Flat namespace; no federation; just call string version return list(name.toString()); }
protected Context c_createSubcontext(Name name, Continuation cont) throws NamingException { if (resolve_to_penultimate_context(name, cont)) return a_createSubcontext(name.toString(), cont); else return null; }
static { for (Name via : Name.values()) { STRING_MAPPING.put(via.toString().toUpperCase(), via); } }
protected void c_rebind(Name name, Object obj, Continuation cont) throws NamingException { if (resolve_to_penultimate_context(name, cont)) a_rebind(name.toString(), obj, cont); }
protected void c_destroySubcontext(Name name, Continuation cont) throws NamingException { if (resolve_to_penultimate_context(name, cont)) a_destroySubcontext(name.toString(), cont); }
@Override public String composeName(String name, String prefix) throws NamingException { Name result = composeName(new CompositeName(name), new CompositeName(prefix)); return result.toString(); }
/** * Return the name parser for the specified name. * * @return the NameParser instance. * @throws NamingException if there is an exception. */ @Override public NameParser getNameParser(Name name) throws NamingException { // Flat namespace; no federation; just call string version return getNameParser(name.toString()); }
/** This context does not treat links specially. A lookup operation is performed. */ @Override public Object lookupLink(Name name) throws NamingException { // Flat namespace; no federation; just call string version return lookupLink(name.toString()); }
/** * Lists the bindings of a context or subcontext. The operation is delegated to the serial * context. * * @return an enumeration of the bindings of the context. * @throws NamingException if there is a naming exception. */ @Override public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { // Flat namespace; no federation; just call string version return listBindings(name.toString()); }
/** * Find a type object in the context of the class. * * @param name The name to search for. */ public Named find(Matcher<Named> matcher, Context context) throws SemanticException { Name name = matcher.name(); if (Report.should_report(TOPICS, 2)) Report.report(2, "Looking for " + name + " in " + this); if (!(type instanceof ClassType)) { throw new NoClassException(name.toString(), type); } ClassType type = (ClassType) this.type; Named m = null; QName fullName = null; QName rawName = null; if (type.isGloballyAccessible()) { fullName = QName.make(type.fullName(), name); QName q = ts.getTransformedClassName(type.def()); rawName = QName.make(q.qualifier(), Name.make(q.name() + "$" + name)); } if (fullName != null) { // First check the system resolver. m = ts.systemResolver().check(fullName); // Try the raw class file name. if (m == null) { m = ts.systemResolver().check(rawName); } if (m == null) { // Go to disk, but only if there is no job for the type. // If there is a job, all members should be in the resolver // already. boolean useLoadedResolver = true; if (type instanceof ParsedTypeObject) { ParsedTypeObject pto = (ParsedTypeObject) type; if (pto.job() != null) { useLoadedResolver = false; } } if (useLoadedResolver) { try { m = ts.systemResolver().find(rawName); } catch (SemanticException e) { // Not found; will fall through to error handling code } } } // If we found something, verify that it matches. if (m != null) { try { m = matcher.instantiate(m); } catch (SemanticException e) { // Doesn't match; try again. m = null; } } } // Check if the member was explicitly declared. if (m == null) { m = type.memberTypeMatching(matcher); } // If we found something, make sure it's accessible. if (m instanceof ClassType) { ClassType mt = (ClassType) m; if (!mt.isMember()) { throw new SemanticException( "Class " + mt + " is not a member class, " + " but was found in " + type + "."); } if (!mt.outer().equals((Object) type)) { throw new SemanticException( "Class " + mt + " is not a member class " + " of " + type + "."); } return mt; } if (m instanceof MemberInstance) { MemberInstance<?> mi = (MemberInstance<?>) m; if (!mi.container().equals((Object) type)) { throw new SemanticException("Type " + mi + " is not a member " + " of " + type + "."); } } if (m != null) { if (!canAccess(m, context.currentClassDef(), context)) { throw new SemanticException("Cannot access member type \"" + m + "\"."); } return m; } // If we struck out, try the super types. // Collect all members of the super types. // Use a Set to eliminate duplicates. Set<Named> acceptable = new HashSet<Named>(); if (type.superClass() != null) { Type sup = type.superClass(); if (sup instanceof ClassType) { Resolver r = ts.classContextResolver((ClassType) sup, context); try { Named n = r.find(matcher); acceptable.add(n); } catch (SemanticException e) { } } } for (Iterator<Type> i = type.interfaces().iterator(); i.hasNext(); ) { Type sup = (Type) i.next(); if (sup instanceof ClassType) { Resolver r = ts.classContextResolver((ClassType) sup, context); try { Named n = r.find(matcher); acceptable.add(n); } catch (SemanticException e) { } } } if (acceptable.size() == 0) { throw new NoClassException(name.toString(), type); } else if (acceptable.size() > 1) { Set<Type> containers = new HashSet<Type>(acceptable.size()); for (Named n : acceptable) { if (n instanceof MemberInstance) { MemberInstance<?> mi = (MemberInstance<?>) n; containers.add(mi.container()); } } if (containers.size() == 2) { Iterator<Type> i = containers.iterator(); Type t1 = (Type) i.next(); Type t2 = (Type) i.next(); throw new SemanticException( "Member \"" + name + "\" of " + type + " is ambiguous; it is defined in both " + t1 + " and " + t2 + "."); } else if (containers.size() == 0) { throw new SemanticException("Member \"" + name + "\" of " + type + " is ambiguous."); } else { throw new SemanticException( "Member \"" + name + "\" of " + type + " is ambiguous; it is defined in " + CollectionUtil.listToString(new ArrayList<Type>(containers)) + "."); } } assert acceptable.size() == 1; Named t = acceptable.iterator().next(); if (Report.should_report(TOPICS, 2)) Report.report(2, "Found member type " + t); return t; }
public void testShouldPutToCustomerNameInTemplateParameters() { requestParams.put("fromCustomer", ben.toString()); requestParams.put("toCustomer", isabella.toString()); Map<String, Object> templateParams = view.process(requestParams); assertEquals(isabellaName.toString(), templateParams.get("toCustomerName").toString()); }
/** * Renders a table cell in the main JTable. As a TableCellRenderer, we have to implement this * method, but we use it to colour different types of matches in different ways. Remember that * this is run every time a cell is displayed on the screen, so it needs to be as fast as can be. * * @param table The table which needs rendering. * @param value The object which needs rendering. For now, this can only be a Name object, but * later on we might colour different types of cells in different ways. * @param isSelected Is this cell selected, i.e. is the row selected? * @param hasFocus Is this cell focused, i.e. is this individual cell selected? * @param row The row coordinate of this cell. * @param column The column coordinate of this cell. * @return A component representing this cell. */ @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { // TODO: Check if we can get a saving out of this by just rendering a JLabel/JTextField // directly. Component c = defTableCellRenderer.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); // Set all backgrounds to white. c.setBackground(Color.WHITE); if (value == null) { // Null values look null-ish. c.setBackground(COLOR_NULL); return c; } else if (hasFocus) { // ANY cell with focus should look focussed. c.setBackground(COLOR_FOCUS); return c; } else if (Name.class.isAssignableFrom(value.getClass())) { // Aha, a Name! Color it special. Name name = (Name) value; int str_length = name.toString().length(); if (currentMatch == null) { // No current match? Then just colour blank cells blank, // and unmatched name colours special so people know that // they have been recognized as names. if (str_length == 0) { c.setBackground(COLOR_BLANK_CELL); } else { c.setBackground(COLOR_NAME_UNMATCHED); } } else { // So which RowIndex is the match against? RowIndex against = currentMatch.getAgainst(); // System.err.println("Checking against: " + against); if (str_length == 0) { // Mark blank cells as such. c.setBackground(COLOR_BLANK_CELL); } else if (against.hasName(name)) { // Perfect match! c.setBackground(COLOR_NAME_FULL_MATCH); } else if (against.hasName(name.getGenus())) { // Genus-match. c.setBackground(COLOR_NAME_GENUS_MATCH); } else { // No match! c.setBackground(COLOR_NAME_NO_MATCH); } } } else { // Not a name? Note that Strings will NOT make it here: we don't // push Strings through this. So this is really just for later. c.setBackground(COLOR_NULL); } // If the row is selected, make it darker. if (isSelected) c.setBackground(c.getBackground().darker()); return c; }