public SIGBase( Name name, int type, int dclass, long ttl, int covered, int alg, long origttl, Date expire, Date timeSigned, int footprint, Name signer, byte[] signature) { super(name, type, dclass, ttl); Type.check(covered); checkU8("alg", alg); checkU8("labels", labels); TTL.check(origttl); checkU16("footprint", footprint); this.covered = covered; this.alg = alg; this.labels = name.labels(); this.origttl = origttl; this.expire = expire; this.timeSigned = timeSigned; this.footprint = footprint; if (!signer.isAbsolute()) throw new RelativeNameException(signer); this.signer = signer; this.signature = signature; }
@Override public boolean endsWith(Name name) { if (!(name instanceof CompoundName)) { return false; } return equals(name, size() - name.size(), name.size()); }
static String getSuiteName(Class<?> klass) throws InitializationError { Name nameAnnotation = klass.getAnnotation(Name.class); if (nameAnnotation == null) { throw new InitializationError("There must be a @Name annotation"); } return nameAnnotation.value(); }
public void destroySubcontext(Name name) throws NamingException { if (name.size() == 0) throw new NamingException(L.l("can't destroy root subcontext")); AbstractModel model = _model; int i = 0; for (; i + 1 < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) { ((Context) value).destroySubcontext(name.getSuffix(i + 1)); return; } else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } String first = name.get(i); model.unbind(first); }
@SuppressWarnings("deprecation") public void testThousandsOfSymbolsWithOldBytes() throws IOException { final int SEED = 33333; BytesToNameCanonicalizer symbolsBRoot = BytesToNameCanonicalizer.createRoot(SEED); final Charset utf8 = Charset.forName("UTF-8"); int exp = 0; for (int doc = 0; doc < 100; ++doc) { BytesToNameCanonicalizer symbolsB = symbolsBRoot.makeChild(JsonFactory.Feature.collectDefaults()); for (int i = 0; i < 250; ++i) { String name = "f_" + doc + "_" + i; int[] quads = BytesToNameCanonicalizer.calcQuads(name.getBytes(utf8)); symbolsB.addName(name, quads, quads.length); Name n = symbolsB.findName(quads, quads.length); assertEquals(name, n.getName()); } symbolsB.release(); exp += 250; if (exp > BytesToNameCanonicalizer.MAX_ENTRIES_FOR_REUSE) { exp = 0; } assertEquals(exp, symbolsBRoot.size()); } }
private Object lookupImpl(Name name) throws NamingException { if (log.isLoggable(Level.FINEST)) log.finest(L.l("JNDI lookup `{0}'", name)); if (name == null) return create(_model, _env); AbstractModel model = _model; for (int i = 0; i < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (i + 1 == name.size()) { return value; } else if (value instanceof Context) { return ((Context) value).lookup(name.getSuffix(i + 1)); } else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } return create(getFullPath(name), model, _env); }
public void rebind(Name name, Object obj) throws NamingException { if (name.size() == 0) throw new NamingException(L.l("can't bind root")); AbstractModel model = _model; int i = 0; for (; i + 1 < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) { ((Context) value).bind(name.getSuffix(i + 1), obj); return; } else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } String first = name.get(i); if (obj == null) obj = NullValue.NULL; model.bind(first, getReference(model, obj)); }
protected SOAPElement convertToSoapElement(Element element) { if (element instanceof SOAPFaultElement) { return (SOAPElement) element; } else if (element instanceof SOAPElement) { SOAPElement soapElement = (SOAPElement) element; if (getDetailName().equals(soapElement.getElementName())) { return replaceElementWithSOAPElement(element, createDetail()); } else { String localName = soapElement.getElementName().getLocalName(); if (isStandardFaultElement(localName)) return replaceElementWithSOAPElement( element, createSOAPFaultElement(soapElement.getElementQName())); return soapElement; } } else { Name elementName = NameImpl.copyElementName(element); ElementImpl newElement; if (getDetailName().equals(elementName)) { newElement = (ElementImpl) createDetail(); } else { String localName = elementName.getLocalName(); if (isStandardFaultElement(localName)) newElement = (ElementImpl) createSOAPFaultElement(elementName); else newElement = (ElementImpl) createElement(elementName); } return replaceElementWithSOAPElement(element, newElement); } }
/** * 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; }
/** * Finds and returns name matching the specified symbol, if such name already exists in the table. * If not, will return null. * * <p>Note: separate methods to optimize common case of relatively short element/attribute names * (8 or less ascii characters) * * @param q1 int32 containing first 4 bytes of the name. * @param q2 int32 containing bytes 5 through 8 of the name; if less than 8 bytes, padded with up * to 3 zero bytes in front (zero MSBs, ie. right aligned) * @return Name matching the symbol passed (or constructed for it) */ public Name findName(int q1, int q2) { int hash = (q2 == 0) ? calcHash(q1) : calcHash(q1, q2); int ix = (hash & _hashMask); int val = _hash[ix]; /* High 24 bits of the value are low 24 bits of hash (low 8 bits * are bucket index)... match? */ if ((((val >> 8) ^ hash) << 8) == 0) { // match // Ok, but do we have an actual match? Name name = _mainNames[ix]; if (name == null) { // main slot empty; can't find return null; } if (name.equals(q1, q2)) { return name; } } else if (val == 0) { // empty slot? no match return null; } // Maybe a spill-over? val &= 0xFF; if (val > 0) { // 0 means 'empty' val -= 1; // to convert from 1-based to 0... Bucket bucket = _collList[val]; if (bucket != null) { return bucket.find(hash, q1, q2); } } // Nope, no match whatsoever return null; }
/** * Finds and returns name matching the specified symbol, if such name already exists in the table; * or if not, creates name object, adds to the table, and returns it. * * <p>Note: this is the general purpose method that can be called for names of any length. * However, if name is less than 9 bytes long, it is preferable to call the version optimized for * short names. * * @param q Array of int32s, each of which contain 4 bytes of encoded name * @param qlen Number of int32s, starting from index 0, in quads parameter * @return Name matching the symbol passed (or constructed for it) */ public Name findName(int[] q, int qlen) { if (qlen < 3) { // another sanity check return findName(q[0], (qlen < 2) ? 0 : q[1]); } int hash = calcHash(q, qlen); // (for rest of comments regarding logic, see method above) int ix = (hash & _hashMask); int val = _hash[ix]; if ((((val >> 8) ^ hash) << 8) == 0) { Name name = _mainNames[ix]; if (name == null // main slot empty; no collision list then either || name.equals(q, qlen)) { // should be match, let's verify return name; } } else if (val == 0) { // empty slot? no match return null; } val &= 0xFF; if (val > 0) { // 0 means 'empty' val -= 1; // to convert from 1-based to 0... Bucket bucket = _collList[val]; if (bucket != null) { return bucket.find(hash, q, qlen); } } return null; }
public static int putClass(String c, boolean p, String sc) { Name cName = Type.getName(c); if ((cName != null) && !Name.isForward(c)) { push(); push(); return 1; } else { Name scName = Type.getName(sc); if (scName == null) { push(); push(); return 2; } else { push(scName.getEnv()); Env current = top; push(); cName = Type.putName(c, sc, top); Symb s = new Symb(cName, cName, p); current.table.put(c, s); System.out.println(" PUT " + c + " IN " + current); root.table.put(c, s); System.out.println(" PUT " + c + " IN " + root); return 0; } } }
private void guessPhoneticNameStyle(Name name) { if (name.phoneticNameStyle != PhoneticNameStyle.UNDEFINED) { return; } int bestGuess = guessPhoneticNameStyle(name.phoneticFamilyName); if (bestGuess != FullNameStyle.UNDEFINED && bestGuess != FullNameStyle.CJK) { name.phoneticNameStyle = bestGuess; return; } int guess = guessPhoneticNameStyle(name.phoneticGivenName); if (guess != FullNameStyle.UNDEFINED) { if (guess != FullNameStyle.CJK) { name.phoneticNameStyle = guess; return; } bestGuess = guess; } guess = guessPhoneticNameStyle(name.phoneticMiddleName); if (guess != FullNameStyle.UNDEFINED) { if (guess != FullNameStyle.CJK) { name.phoneticNameStyle = guess; return; } bestGuess = guess; } }
public SOAPElement addAttribute(Name name, String value) throws SOAPException { addAttributeBare(name, value); if (!"".equals(name.getURI())) { ensureNamespaceIsDeclared(name.getPrefix(), name.getURI()); } return this; }
private static String nameOf(Method method) { Name name = method.getAnnotation(Name.class); if (name != null) { return name.value(); } return method.getName(); }
public void testLinenoTry() { AstRoot root = parse( "\ntry {\n" + " var x = 1;\n" + "} catch\n" + " (err)\n" + "{\n" + "} finally {\n" + " var y = 2;\n" + "}\n"); TryStatement tryStmt = (TryStatement) root.getFirstChild(); AstNode tryBlock = tryStmt.getTryBlock(); List<CatchClause> catchBlocks = tryStmt.getCatchClauses(); CatchClause catchClause = catchBlocks.get(0); Block catchVarBlock = catchClause.getBody(); Name catchVar = catchClause.getVarName(); AstNode finallyBlock = tryStmt.getFinallyBlock(); AstNode finallyStmt = (AstNode) finallyBlock.getFirstChild(); assertEquals(1, tryStmt.getLineno()); assertEquals(1, tryBlock.getLineno()); assertEquals(5, catchVarBlock.getLineno()); assertEquals(4, catchVar.getLineno()); assertEquals(3, catchClause.getLineno()); assertEquals(6, finallyBlock.getLineno()); assertEquals(7, finallyStmt.getLineno()); }
@Test @Priority(10) public void initData() { Session session = openSession(); // Rev 1 session.getTransaction().begin(); Person p = new Person(); Name n = new Name(); n.setName("name1"); p.getNames().add(n); session.saveOrUpdate(p); session.getTransaction().commit(); // Rev 2 session.getTransaction().begin(); n.setName("Changed name"); session.saveOrUpdate(p); session.getTransaction().commit(); // Rev 3 session.getTransaction().begin(); Name n2 = new Name(); n2.setName("name2"); p.getNames().add(n2); session.getTransaction().commit(); personId = p.getId(); }
@Override protected void onPostExecute(String result) { // Log.e("Joseph", result); Gson gson = new Gson(); Authorisation auth = gson.fromJson(result, Authorisation.class); String error = auth.getError(); if (error.equals("false")) { // User has logged in successfully and api key has been issued // Send data to FragmentActivity by hooking into UI event APIKEY = auth.getApikey(); if (mListener != null) { String[] authDetails = {auth.getName(), auth.getEmail(), auth.getApikey()}; mListener.onFragmentInteraction(authDetails); Toast.makeText(getActivity(), auth.getMessage(), Toast.LENGTH_SHORT).show(); // Update the list in the Drawer so that it can show logout CloseFragment(); } } else { // Login failed because error was returned from service registerFailed.setText(auth.getMessage()); registerFailed.setTextColor(Color.RED); Name.setText(""); Email.setText(""); Password.setText(""); ConfirmPassword.setText(""); Name.requestFocus(); } }
/** Looks up an object with the given parsed JNDI name, but don't dereference the final object. */ public Object lookupLink(Name name) throws NamingException { if (name == null) return create(_model, _env); AbstractModel model = _model; for (int i = 0; i < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } if (i + 1 == name.size()) { if (value == NullValue.NULL) return null; else if (value != null) return value; else throw new NameNotFoundException(getFullPath(name)); } value = dereference(value, null, model); if (value instanceof Context) return ((Context) value).lookupLink(name.getSuffix(i + 1)); else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } return create(getFullPath(name), model, _env); }
public String[] sort(String[] names) { List<String> namesWeight = new ArrayList<String>(); // john 47 List<Name> list = new ArrayList<Name>(); for (int i = 0; i < names.length; i++) { String value = names[i]; if (value.equals("JOHN")) { namesWeight.add(value); } else { int temp = calculatevalue(value); Name n = new Name(); n.name = names[i]; n.sum = temp; n.order = i; list.add(n); } } Collections.sort(list); for (Name n : list) { namesWeight.add(n.name); } for (int i = 0; i < names.length; i++) { names[i] = namesWeight.get(i); } return names; }
/** Lists the names for the context. */ public NamingEnumeration list(Name name) throws NamingException { AbstractModel model = _model; if (name == null) { return new QNameClassEnumeration(create(model, _env), model.list()); } for (int i = 0; i < name.size(); i++) { String first = name.get(i); Object value = model.lookup(first); if (value instanceof AbstractModel) { model = (AbstractModel) value; continue; } value = dereference(value, null, model); if (value instanceof Context) return ((Context) value).list(name.getSuffix(i + 1)); else if (value != null) throw new NotContextException( L.l("{0}: expected intermediate context at `{1}'", getFullPath(name), value)); else throw new NameNotFoundException(getFullPath(name)); } return new QNameClassEnumeration(create(model, _env), model.list()); }
/** Parses the output of winipcfg or ipconfig. */ private static void findWin(InputStream in) { BufferedReader br = new BufferedReader(new InputStreamReader(in)); try { List lserver = new ArrayList(); List lsearch = new ArrayList(); String line = null; boolean readingServers = false; boolean readingSearches = false; while ((line = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); if (!st.hasMoreTokens()) { readingServers = false; readingSearches = false; continue; } String s = st.nextToken(); if (line.indexOf(":") != -1) { readingServers = false; readingSearches = false; } if (line.indexOf("Host Name") != -1) { while (st.hasMoreTokens()) s = st.nextToken(); Name name; try { name = Name.fromString(s, null); } catch (TextParseException e) { continue; } if (name.labels() == 1) continue; addSearch(s, lsearch); } else if (line.indexOf("Primary Dns Suffix") != -1) { while (st.hasMoreTokens()) s = st.nextToken(); if (s.equals(":")) continue; addSearch(s, lsearch); readingSearches = true; } else if (readingSearches || line.indexOf("DNS Suffix") != -1) { while (st.hasMoreTokens()) s = st.nextToken(); if (s.equals(":")) continue; addSearch(s, lsearch); readingSearches = true; } else if (readingServers || line.indexOf("DNS Servers") != -1) { while (st.hasMoreTokens()) s = st.nextToken(); if (s.equals(":")) continue; addServer(s, lserver); readingServers = true; } } if (servers == null && lserver.size() > 0) servers = (String[]) lserver.toArray(new String[lserver.size()]); } catch (IOException e) { } finally { try { br.close(); } catch (IOException e) { } } return; }
@BeforeClass(dependsOnMethods = "init") public void initData() { newSessionFactory(); // Rev 1 getSession().getTransaction().begin(); Person p = new Person(); Name n = new Name(); n.setName("name1"); p.getNames().add(n); getSession().saveOrUpdate(p); getSession().getTransaction().commit(); // Rev 2 getSession().getTransaction().begin(); n.setName("Changed name"); getSession().saveOrUpdate(p); getSession().getTransaction().commit(); // Rev 3 getSession().getTransaction().begin(); Name n2 = new Name(); n2.setName("name2"); p.getNames().add(n2); getSession().getTransaction().commit(); personId = p.getId(); }
/** * Determines whether a compound name is a suffix of this compound name. A compound name 'n' is a * suffix if it it is equal to getSuffix(size()-n.size())--in other words, this compound name ends * with 'n'. If n is null or not a compound name, false is returned. * * <p>Implementation note: Currently the syntax properties of n are not used when doing the * comparison. They might be in the future. * * @param n The possibly null compound name to check. * @return true if n is a CompoundName and is a suffix of this compound name, false otherwise. */ public boolean endsWith(Name n) { if (n instanceof CompoundName) { return (impl.endsWith(n.size(), n.getAll())); } else { return false; } }
public String getUserField(String claimUri) { claimUri = claimUri.trim(); if (claimUri == null || claimUri.trim().equals("")) { return null; } String userField = null; if (SocialImplConstants.CLAIM_URI_DISPLAY_NAME.equals(claimUri)) { return displayName; } else if (SocialImplConstants.CLAIM_URI_GIVEN_NAME.equals(claimUri)) { return name.getGivenName(); } else if (SocialImplConstants.CLAIM_URI_FAMILY_NAME.equals(claimUri)) { return name.getFamilyName(); } else if (SocialImplConstants.CLAIM_URI_NICK_NAME.equals(claimUri)) { return nickname; } else if (SocialImplConstants.CLAIM_URI_ORGANIZATION.equals(claimUri)) { return organizations.get(0).getName(); } else if (SocialImplConstants.CLAIM_URI_STREET_ADDRESS.equals(claimUri)) { return addresses.get(0).getStreetAddress(); } else if (SocialImplConstants.CLAIM_URI_COUNTRY.equals(claimUri)) { return addresses.get(0).getCountry(); } else if (SocialImplConstants.CLAIM_URI_EMAIL.equals(claimUri)) { return emails.get(0).getValue(); } else if (SocialImplConstants.CLAIM_URI_PHONE_NUMBER.equals(claimUri)) { return phoneNumbers.get(0).getValue(); } else if (SocialImplConstants.CLAIM_URI_IM.equals(claimUri)) { return ims.get(0).getValue(); } else if (SocialImplConstants.CLAIM_URI_URL.equals(claimUri)) { return urls.get(0).getValue(); } else { return null; } // TODO: Add other fields }
/** * 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()); } }
/** * 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()); } }
@Test public void convertToSequence() { Folder c = db.createFolder("/top"); c.documents().build(Name.create(db, "one")).elem("test").end("test").commit(); XMLDocument doc = c.documents().build(Name.create(db, "two")).elem("test").end("test").commit(); assertEquals(2, c.query().all("/test").size()); assertEquals(1, c.query().all("$_1/test", new Object[] {doc}).size()); }
/** 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; }
public NameParser getNameParser(Name name) throws NamingException { if (name.size() == 0) return new QNameParser(this); Object obj = lookupSingleObject(name.get(0)); if (obj instanceof Context) return ((Context) obj).getNameParser(name.getSuffix(1)); else return new QNameParser(this); }