/** * Loads nested schema type definitions from wsdl. * * @throws IOException * @throws WSDLException * @throws TransformerFactoryConfigurationError * @throws TransformerException * @throws TransformerConfigurationException */ private void loadSchemas() throws WSDLException, IOException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError { Definition definition = WSDLFactory.newInstance().newWSDLReader().readWSDL(wsdl.getFile().getAbsolutePath()); Types types = definition.getTypes(); List<?> schemaTypes = types.getExtensibilityElements(); for (Object schemaObject : schemaTypes) { if (schemaObject instanceof SchemaImpl) { SchemaImpl schema = (SchemaImpl) schemaObject; inheritNamespaces(schema, definition); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Source source = new DOMSource(schema.getElement()); Result result = new StreamResult(bos); TransformerFactory.newInstance().newTransformer().transform(source, result); Resource schemaResource = new ByteArrayResource(bos.toByteArray()); schemas.add(schemaResource); if (definition .getTargetNamespace() .equals(schema.getElement().getAttribute("targetNamespace"))) { setXsd(schemaResource); } } else { log.warn("Found unsupported schema type implementation " + schemaObject.getClass()); } } }
/** * Parse out a list of {@link Definition} from the provided text description. * * <p>The format expected here is one definition per line; using the format * "name=...expression..". * * @param definition * @return List of definition */ public static List<Definition> toDefinition(String definition) { List<Definition> list = new ArrayList<Definition>(); HashSet<String> check = new HashSet<String>(); // clean up cross platform differences of line feed String[] defs = splitDefinitions(definition); for (String line : defs) { int mark = line.indexOf("="); if (mark != -1) { String name = line.substring(0, mark).trim(); String expressionDefinition = line.substring(mark + 1).trim(); if (check.contains(name)) { throw new IllegalArgumentException("Attribute " + name + " defined more than once"); } Expression expression; try { expression = ECQL.toExpression(expressionDefinition); } catch (CQLException e) { throw new IllegalArgumentException( "Unable to parse expression " + name + "=" + expressionDefinition + " " + e, e); } Definition def = new Definition(); def.name = name; def.expression = expression; list.add(def); check.add(name); // to catch duplicates! } } return list; }
/** Add a symbol to our scope */ void add(Definition def) { // Check to see if we already have a definition Definition oldDef = (Definition) elements.get(def.getName()); // If so, we'll create a MultiDef to hold them if (oldDef != null) { // If the symbol there so far was not a MultiDef if (!(oldDef instanceof MultiDef)) { // remove the old definition elements.remove(oldDef); // create a new MultiDef MultiDef newMulti = new MultiDef(def.getName(), oldDef); // add the old symbol to the MultiDef newMulti.addDef(oldDef); oldDef = newMulti; // add the MultiDef back into the scope elements.put(def.getName(), oldDef); } // We now have a multidef, so add the new symbol to it ((MultiDef) oldDef).addDef(def); } // Otherwise, just add the new symbol to the scope else { elements.put(def.getName(), def); def.setParentScope(this); } }
/** @param args */ public static void main(String[] args) { try { // Authenticate System.out.println("Creating user..."); User user = new User(Config.username, Config.api_key); // Create the definition Definition d = user.createDefinition("interaction.sample < 1.0"); // Create the consumer System.out.println("Getting the consumer..."); StreamConsumer consumer = d.getConsumer(StreamConsumer.TYPE_HTTP, new Deletes()); // And start consuming System.out.println("Consuming..."); System.out.println("--"); consumer.consume(); } catch (EInvalidData e) { System.out.print("InvalidData: "); System.out.println(e.getMessage()); } catch (ECompileFailed e) { System.out.print("CompileFailed: "); System.out.println(e.getMessage()); } catch (EAccessDenied e) { System.out.print("AccessDenied: "); System.out.println(e.getMessage()); } }
@Override public String toString(int level) { StringBuilder sb = new StringBuilder(); if (this.definitions == null) { sb.append("struct { }"); // $NON-NLS-1$ } else { if (this.definitions.size() == 0) { sb.append("struct { }"); // $NON-NLS-1$ } else { sb.append("struct {\n"); // $NON-NLS-1$ List<String> keys = this.declaration.getFieldsList(); for (int i = 0; i < keys.size() - 1; ++i) { String key = keys.get(i); Definition def = this.definitions.get(key); sb.append(Definition.getIndentString(level + 1) + key + ": "); // $NON-NLS-1$ sb.append(def.toString(level + 1)); sb.append(",\n"); // $NON-NLS-1$ } sb.append( Definition.getIndentString(level + 1) + keys.get(this.definitions.size() - 1) + ": "); //$NON-NLS-1$ sb.append( this.definitions.get(keys.get(keys.size() - 1)).toString(level + 1) + "\n"); //$NON-NLS-1$ sb.append(Definition.getIndentString(level) + "}"); // $NON-NLS-1$ } } return sb.toString(); }
/** * Test the hierachy process. This test verify bug, that caused codes to be badly resolve, is * fixed. */ @Test public void testHierachyBug() { RPClass b = new RPClass("RPClassTest::K"); b.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD); b.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.STANDARD); b.add(DefinitionClass.STATIC, "c", "test", Definition.STANDARD); RPClass c = new RPClass("RPClassTest::M"); c.isA(b); c.add(DefinitionClass.ATTRIBUTE, "a", Type.STRING, Definition.STANDARD); c.add(DefinitionClass.STATIC, "c", "subclass", Definition.STANDARD); Attributes attr = new Attributes(c); attr.put("a", 10); assertTrue(attr.has("a")); assertFalse(attr.has("b")); assertTrue(attr.has("c")); assertEquals("subclass", attr.get("c")); Definition def = c.getDefinition(DefinitionClass.ATTRIBUTE, "a"); assertEquals(Type.STRING, def.getType()); short code = def.getCode(); assertEquals("a", c.getName(DefinitionClass.ATTRIBUTE, code)); }
private static RaiseException templateError( ThreadContext ctx, String message, HashAdapter definition) { Definition d = new Definition(definition, null); String codec = d.getCodec(ctx).asJavaString(); String name = d.getName().orNull(); return Errors.newASN1Error( ctx.getRuntime(), "Error while processing(" + codec + "|" + name + ") " + message); }
/** * Uses a VariableReplacer to replace the appropriate variable in the term which is calculated * until now. */ @Override public Definition define(Definition definition) { if (definition == null || definition.getTerm() == null) { return null; } Replacement replacement = new Replacement(definition.getVariable(), definition.getTerm()); VariableReplacer variableReplacer = new VariableReplacer(replacement); wp = variableReplacer.replace(wp); return null; }
public void processDocument(Document docProcess, Object objCurrent) throws NotesException { for (Iterator<Definition> itDefinition = m_Definition.iterator(); itDefinition.hasNext(); ) { Definition defCurrent = itDefinition.next(); defCurrent .getBinder() .processJava2Domino( docProcess, objCurrent, defCurrent.getNotesField(), defCurrent.getJavaField(), defCurrent.getAdditionalValues()); } }
/** * Lookup a method in the scope This is usually just a hashtable lookup, but if the element * returned is a MultiDef, we need to ask it to find the best match */ Definition lookup(String name, int numParams) { // Try to find the name in our scope Definition d = (Definition) elements.get(name); // if we found multiple defs of the same name, ask the multidef // to do the resolution for us. if (d instanceof MultiDef) return d.lookup(name, numParams); // if we got a method back, check to see that the params apply else if (d instanceof MethodDef) if (((MethodDef) d).getParamCount() == numParams) return d; else return null; else return d; }
@Override public void read(String name, IReader reader) { reader.openStruct(this, name); // Browse all fields final List<String> fieldList = this.declaration.getFieldsList(); for (String fName : fieldList) { Definition def = this.definitions.get(fName); assert (def != null); def.read(fName, reader); } reader.closeStruct(this, name); }
@Override public long getSize(long offset) { // Align long at = Definition.align(offset, this.declaration.getAlignment()); // Browse all fields final List<String> fieldList = this.declaration.getFieldsList(); for (String fName : fieldList) { Definition def = this.definitions.get(fName); assert (def != null); at += def.getSize(at); } return at - offset; }
private Definition parseEvent(XMLEvent event, Definition def) { StartElement se = event.asStartElement(); String elementName = se.getName().getLocalPart(); if (elementName.equals("catalog")) { return null; } Iterator<Attribute> attributes = se.getAttributes(); if (def == null) { Attribute id = attributes.next(); if (id.getName().toString() != ID) { throw new RuntimeException( "At line " + event.getLocation().getLineNumber() + ", problem with definition '" + elementName + "'. The first attribute of a definition must be called '" + ID + "'."); } def = new Definition(elementName, id.getValue()); // LogUtil.logger.info("def cree "+def.type+" - "+def.id); } else { DefElement de = new DefElement(elementName); while (attributes.hasNext()) { Attribute a = attributes.next(); de.addVal(a.getName().toString(), a.getValue()); } def.getElements().add(de); // LogUtil.logger.info(" element ajouté : "+de.name+" - "+de.getVal()); } return def; }
@Override public final ForcedType getConfiguredForcedType( Definition definition, DataTypeDefinition definedType) { for (ForcedType forcedType : getConfiguredForcedTypes()) { String expression = forcedType.getExpression(); if (forcedType.getExpressions() != null) { expression = forcedType.getExpressions(); log.warn( "DEPRECATED", "The <expressions/> element in <forcedType/> is deprecated. Use <expression/> instead"); } String types = forcedType.getTypes(); boolean match = true; if (expression != null && !definition.getQualifiedName().matches(expression)) { match = false; } if (types != null && definedType != null && !definedType.getType().matches(types)) { match = false; } if (match) { return forcedType; } } return null; }
public static Definition setConfiguration( Definition node, org.kframework.kil.loader.Context context, final Configuration conf) { try { return (Definition) node.accept( new CopyOnWriteTransformer("Configuration setter", context) { @Override public ASTNode transform(Configuration node) { return conf; } @Override public ASTNode transform(org.kframework.kil.Context node) { return node; } @Override public ASTNode transform(Rule node) { return node; } @Override public ASTNode transform(Syntax node) { return node; } }); } catch (TransformerException e) { e.printStackTrace(); } return node; }
/** * This test case shows a bug fix for a Marauroa 1.3x bug where two attributes definition even in * diferent classes where created as the same one ( ignoring the second definition ). * * <p>For example A ( id string ) B ( id int ) * * <p>They are different attributes and of different type. Check that it is true. */ @Test public void testGlobalDefinitionBug() { RPClass b = new RPClass("RPClassTest::G"); b.add(DefinitionClass.ATTRIBUTE, "a", Type.INT, Definition.STANDARD); b.add(DefinitionClass.ATTRIBUTE, "b", Type.FLAG, Definition.STANDARD); RPClass c = new RPClass("H"); c.add(DefinitionClass.ATTRIBUTE, "a", Type.STRING, Definition.STANDARD); c.add(DefinitionClass.ATTRIBUTE, "b", Type.FLOAT, Definition.HIDDEN); Definition defb = b.getDefinition(DefinitionClass.ATTRIBUTE, "a"); Definition defc = c.getDefinition(DefinitionClass.ATTRIBUTE, "a"); assertFalse(defb.getType() == defc.getType()); }
/** * Print a list of definitions in different format: fqdn, vdlt, and vdlx * * @param writer the target to output the list * @param defList a list of definitions * @param format the output format * @see #FORMAT_FQDN * @see #FORMAT_VDLT * @see #FORMAT_VDLX NOTE: might be better to move into another module? */ public void printDefinitionList(Writer writer, java.util.List defList, int format) throws IOException { if (defList == null || defList.isEmpty()) return; Definitions defs = new Definitions(); if (format != FORMAT_FQDN) { defs.setDefinition(defList); if (format == FORMAT_VDLX) defs.toXML(writer, ""); else if (format == FORMAT_VDLT) defs.toString(writer); } else { for (Iterator i = defList.iterator(); i.hasNext(); ) { Definition def = (Definition) i.next(); writer.write(def.identify()); writer.write("\n"); } writer.flush(); } }
/** * Initialise the object. * * @param user The user this consumer should run as. * @param definition The definition this consumer will consume. * @throws EAccessDenied * @throws ECompileFailed * @throws EInvalidData */ protected void Init(User user, Definition definition, boolean isHistoric) throws EInvalidData, ECompileFailed, EAccessDenied { // Set the user _user = user; // Set the definition _definition = definition; // If we have a definition, compile it to ensure it's valid for use if (_definition != null) { if (_definition.getHash().isEmpty()) { _definition.compile(); } } // Set whether this is a historic consumer _is_historic = isHistoric; }
/** * This method adds the given Definition to whatever storage is implemented underneath. * * @param d is the Definition that is ready to be stored. * @return true, if new version was stored and database modified */ public boolean store(VDL d) { if (d instanceof Definition) { this.m_memory = (Definition) d; Logging.instance().log("chunk", 0, "found " + m_memory.shortID()); return true; } else { Logging.instance().log("chunk", 0, "not a definition: " + d.toString()); return false; } }
/** Resolve referenced names */ void resolveTypes(SymbolTable symbolTable) { symbolTable.pushScope(this); // push the current scope elements.resolveTypes(symbolTable); // resolve elements in this scope if (unresolvedStuff != null) { // resolve refs to other syms unresolvedStuff.resolveRefs(symbolTable); unresolvedStuff = null; } symbolTable.popScope(); // pop back out of the scope super.resolveTypes(symbolTable); // let superclass resolve if needed }
protected void copyDefinitionData(ComplexTypeDefinition clone) { super.copyDefinitionData(clone); clone.superType = this.superType; clone.containerMarker = this.containerMarker; clone.objectMarker = this.objectMarker; clone.xsdAnyMarker = this.xsdAnyMarker; clone.extensionForType = this.extensionForType; clone.compileTimeClass = this.compileTimeClass; clone.itemDefinitions.addAll(this.itemDefinitions); }
@Override public final ForcedType getConfiguredForcedType(Definition definition) { for (ForcedType forcedType : getConfiguredForcedTypes()) { if (definition.getQualifiedName().matches(forcedType.getExpressions())) { return forcedType; } } return null; }
@Override public MustDef apply(MustDef a, MustDef b) { MustDef result = new MustDef(); Map<Var, Definition> resultMap = result.reachingDef; // Take the join of all variables that are not TOP in this. for (Var var : a.reachingDef.keySet()) { Definition aDef = a.reachingDef.get(var); if (aDef == null) { // "a" is BOTTOM implies that the variable has more than one possible // definition. We set the join of this to be BOTTOM regardless of what // "b" might be. resultMap.put(var, null); continue; } Node aNode = aDef.node; if (b.reachingDef.containsKey(var)) { Definition bDef = b.reachingDef.get(var); if (aDef.equals(bDef)) { resultMap.put(var, aDef); } else { resultMap.put(var, null); } } else { resultMap.put(var, aDef); } } // Take the join of all variables that are not TOP in other but it is TOP // in this. for (Var var : b.reachingDef.keySet()) { if (!a.reachingDef.containsKey(var)) { resultMap.put(var, b.reachingDef.get(var)); } } return result; }
public int compareTo(Definition definition) { long primaryKey = definition.getPrimaryKey(); if (getPrimaryKey() < primaryKey) { return -1; } else if (getPrimaryKey() > primaryKey) { return 1; } else { return 0; } }
public void readFile() { String log = "updated : "; boolean notempty = false; for (String fileName : filesToRead) { try { notempty = true; log = log.concat(fileName + ", "); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); InputStream in = null; if (GoldMonkeyAppState.external) in = new FileInputStream(fileName); else in = this.getClass().getResourceAsStream(fileName); XMLEventReader eventReader = inputFactory.createXMLEventReader(in); Definition def = null; // read the XML document while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); if (event.isStartElement()) { def = parseEvent(event, def); } else if (event.isEndElement()) { String elementName = event.asEndElement().getName().getLocalPart(); if (def != null && elementName.equals(def.getType())) { BuilderManager.submit(def); def = null; } // else // throw new // RuntimeException("("+fileName+") At line "+event.getLocation().getLineNumber()+", // find a closing element that is not closing a definition"+elementName); } } } catch (FileNotFoundException | XMLStreamException e) { e.printStackTrace(); } } if (notempty) { BuilderManager.buildLinks(); } }
@Test public void testExtractMetadataFromFlvVideo() { File file = flvFile; MetaData result = instance.extractMetadata(file); assertThat(result, is(notNullValue())); assertThat(result.getSilverId(), nullValue()); assertThat(result.getSilverName(), nullValue()); assertThat(result.getMemoryData().getSizeAsLong(), is(file.length())); assertThat(result.getDefinition(), is(Definition.of(1280, 720))); assertThat(result.getFramerate().intValue(), is(25)); assertThat(result.getDuration().getTimeAsLong(), is(6120l)); assertThat(result.getDuration().getFormattedDurationAsHMSM(), is("00:00:06.120")); assertThat(result.getDuration().getFormattedDurationAsHMS(), is("00:00:06")); }
private void walkBindingNode( final Compiler.Context context, final AST node, final Definition message) { List<AST> children = node.getChildNodes(); final String identifier = getString(children.get(0)); final Binding binding = message.createLanguageBinding(identifier); for (int i = 1; i < children.size(); i += 2) { final String key = getString(children.get(i)); final String value = getString(children.get(i + 1)); final Binding.Data prev = binding.getData(key); if (prev != null) { context.error( node.getCodePosition(), identifier + " language binding for " + message.getName() + " already defined for '" + key + "'"); context.warning(prev.getCodePosition(), "this was the location of the previous definition"); } binding.setData(key, value, node.getCodePosition()); } }
/** * Generate the display of the results of the Define command * * @param data the result of the Define command * @param word the queried word * @return the formatted result */ private String retrieveDefine(List<Definition> data, String word) { StringBuffer res = new StringBuffer(); Definition def; for (int i = 0; i < data.size(); i++) { def = data.get(i); if (i != 0 && data.size() > 0) { res.append("<hr>"); } res.append(def.getDefinition().replaceAll("\n", "<br>")) .append("<div align=\"right\"><font size=\"-2\">-- From ") .append(def.getDictionary()) .append("</font></div>"); } String result = res.toString(); result = formatResult(result, "\\\\", "<em>", "</em>"); result = formatResult(result, "[\\[\\]]", "<cite>", "</cite>"); result = formatResult(result, "[\\{\\}]", "<strong>", "</strong>"); result = formatWordDefined(result, word); return result; }
public static Configuration getConfiguration( Definition node, org.kframework.kil.loader.Context context) { final List<Configuration> result = new LinkedList<Configuration>(); node.accept( new BasicVisitor(context) { @Override public void visit(Configuration node) { result.add(node); } @Override public void visit(org.kframework.kil.Context node) { return; } @Override public void visit(Rule node) { return; } @Override public void visit(Syntax node) { return; } }); if (result.size() == 0) { GlobalSettings.kem.register( new KException( ExceptionType.ERROR, KExceptionGroup.INTERNAL, "Internal compiler error --- Cannot find configuration.", node.getFilename(), node.getLocation())); } return result.get(0); }
@Test public void testExtractMetadataFromTifImage() { File file = tifFile; MetaData result = instance.extractMetadata(file); assertThat(result, is(notNullValue())); assertThat(result.getTitle(), is("Logo Silverpeas")); assertThat(result.getSubject(), is("silverpeas")); assertThat(result.getAuthor(), is("AuroreAllibe")); assertThat(result.getComments(), is("Logo silverpeas txt noir")); assertThat(result.getKeywords(), is(notNullValue())); assertThat(result.getKeywords().length, is(2)); assertThat(result.getKeywords()[0], is("silverpeas")); assertThat(result.getKeywords()[1], is("logo")); assertThat(result.getSilverId(), is(nullValue())); assertThat(result.getSilverName(), is(nullValue())); assertThat(result.getCreationDate().getTime(), is(1340963223000L)); assertThat(result.getLastSaveDateTime(), is(nullValue())); assertThat(result.getMemoryData().getSizeAsLong(), is(file.length())); assertThat(result.getDefinition(), is(Definition.of(1942, 1309))); assertThat(result.getFramerate(), nullValue()); assertThat(result.getDuration(), nullValue()); }