Search in sources :

Example 11 with NotImplementedException

use of org.apache.commons.lang.NotImplementedException in project tmdm-common by Talend.

the class MetadataRepository method createFieldMetadata.

// TODO Refactor!
private FieldMetadata createFieldMetadata(XSDElementDeclaration element, ComplexTypeMetadata containingType, int minOccurs, int maxOccurs) {
    String fieldName = element.getName();
    if (maxOccurs > 0 && minOccurs > maxOccurs) {
        // Eclipse XSD does not check this
        throw new IllegalArgumentException("Can not parse information on field '" + element.getQName() + "' of type '" + containingType + "' (maxOccurs > minOccurs)");
    }
    boolean isMany = maxOccurs == -1 || maxOccurs > 1;
    XmlSchemaAnnotationProcessorState state = new XmlSchemaAnnotationProcessorState();
    try {
        XSDAnnotation annotation = element.getAnnotation();
        for (XmlSchemaAnnotationProcessor processor : XML_ANNOTATIONS_PROCESSORS) {
            processor.process(this, containingType, annotation, state);
        }
    } catch (Exception e) {
        throw new RuntimeException("Annotation processing exception while parsing info for field '" + fieldName + "' in type '" + containingType.getName() + "'", e);
    }
    boolean isMandatory = minOccurs > 0;
    boolean isContained = false;
    boolean isReference = state.isReference();
    boolean fkIntegrity = state.isFkIntegrity();
    boolean fkIntegrityOverride = state.isFkIntegrityOverride();
    List<FieldMetadata> foreignKeyInfo = state.getForeignKeyInfo();
    String foreignKeyInfoFormat = state.getForeignKeyInfoFormat();
    TypeMetadata fieldType = state.getFieldType();
    FieldMetadata referencedField = state.getReferencedField();
    TypeMetadata referencedType = state.getReferencedType();
    List<String> hideUsers = state.getHide();
    List<String> allowWriteUsers = state.getAllowWrite();
    List<String> workflowAccessRights = state.getWorkflowAccessRights();
    String visibilityRule = state.getVisibilityRule();
    XSDTypeDefinition schemaType = element.getType();
    if (schemaType instanceof XSDSimpleTypeDefinition) {
        XSDSimpleTypeDefinition simpleSchemaType = (XSDSimpleTypeDefinition) schemaType;
        XSDSimpleTypeDefinition content = simpleSchemaType.getBaseTypeDefinition();
        if (schemaType.getQName() != null) {
            fieldType = new SoftTypeRef(this, schemaType.getTargetNamespace(), schemaType.getName(), false);
        } else {
            // Null QNames may happen for anonymous types extending other types.
            fieldType = new SimpleTypeMetadata(targetNamespace, ANONYMOUS_PREFIX + String.valueOf(anonymousCounter++));
            if (content != null) {
                fieldType.addSuperType(new SoftTypeRef(this, content.getTargetNamespace(), content.getName(), false));
            }
        }
        setFieldData(simpleSchemaType, fieldType);
        fieldType.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
        fieldType.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
        fieldType.setData(XSD_DOM_ELEMENT, element.getElement());
        fieldType.setData(MIN_OCCURS, minOccurs);
        fieldType.setData(MAX_OCCURS, maxOccurs);
        if (isReference) {
            ReferenceFieldMetadata referenceField = new ReferenceFieldMetadata(containingType, false, isMany, isMandatory, fieldName, (ComplexTypeMetadata) referencedType, referencedField, foreignKeyInfo, foreignKeyInfoFormat, fkIntegrity, fkIntegrityOverride, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, state.getForeignKeyFilter(), visibilityRule);
            referenceField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
            referenceField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
            referenceField.setData(XSD_ELEMENT, element);
            referenceField.setData(XSD_DOM_ELEMENT, element.getElement());
            referenceField.setData(MIN_OCCURS, minOccurs);
            referenceField.setData(MAX_OCCURS, maxOccurs);
            setLocalizedNames(referenceField, state.getLocaleToLabel());
            setLocalizedDescriptions(referenceField, state.getLocaleToDescription());
            setDefaultValueRule(referenceField, state.getDefaultValueRule());
            setFieldData(simpleSchemaType, referenceField);
            return referenceField;
        }
        if (content != null) {
            if (content.getFacets().size() > 0) {
                boolean isEnumeration = false;
                for (int i = 0; i < content.getFacets().size(); i++) {
                    XSDConstrainingFacet item = content.getFacets().get(i);
                    if (item instanceof XSDEnumerationFacet) {
                        isEnumeration = true;
                    }
                }
                if (isEnumeration) {
                    EnumerationFieldMetadata enumField = new EnumerationFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
                    enumField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
                    enumField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
                    enumField.setData(XSD_ELEMENT, element);
                    enumField.setData(XSD_DOM_ELEMENT, element.getElement());
                    enumField.setData(MIN_OCCURS, minOccurs);
                    enumField.setData(MAX_OCCURS, maxOccurs);
                    setLocalizedNames(enumField, state.getLocaleToLabel());
                    setLocalizedDescriptions(enumField, state.getLocaleToDescription());
                    setDefaultValueRule(enumField, state.getDefaultValueRule());
                    setFieldData(simpleSchemaType, enumField);
                    return enumField;
                } else {
                    FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
                    field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
                    field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
                    field.setData(XSD_ELEMENT, element);
                    field.setData(XSD_DOM_ELEMENT, element.getElement());
                    field.setData(MIN_OCCURS, minOccurs);
                    field.setData(MAX_OCCURS, maxOccurs);
                    setLocalizedNames(field, state.getLocaleToLabel());
                    setLocalizedDescriptions(field, state.getLocaleToDescription());
                    setDefaultValueRule(field, state.getDefaultValueRule());
                    setFieldData(simpleSchemaType, field);
                    return field;
                }
            } else {
                FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
                field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
                field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
                field.setData(XSD_ELEMENT, element);
                field.setData(XSD_DOM_ELEMENT, element.getElement());
                field.setData(MIN_OCCURS, minOccurs);
                field.setData(MAX_OCCURS, maxOccurs);
                setLocalizedNames(field, state.getLocaleToLabel());
                setLocalizedDescriptions(field, state.getLocaleToDescription());
                setDefaultValueRule(field, state.getDefaultValueRule());
                setFieldData(simpleSchemaType, field);
                return field;
            }
        }
    }
    if (fieldType == null) {
        String qName = element.getType() == null ? null : element.getType().getQName();
        if (qName != null) {
            TypeMetadata metadata = getType(element.getType().getTargetNamespace(), element.getType().getName());
            if (metadata != null) {
                fieldType = new SoftTypeRef(this, targetNamespace, schemaType.getName(), false);
                isContained = true;
            } else {
                if (schemaType instanceof XSDComplexTypeDefinition) {
                    fieldType = new SoftTypeRef(this, schemaType.getTargetNamespace(), schemaType.getName(), false);
                    isContained = true;
                } else {
                    throw new NotImplementedException("Support for '" + schemaType.getClass() + "'.");
                }
            }
        } else {
            // Ref & anonymous complex type
            isContained = true;
            XSDElementDeclaration refName = element.getResolvedElementDeclaration();
            if (schemaType != null) {
                fieldType = new ComplexTypeMetadataImpl(targetNamespace, ANONYMOUS_PREFIX + String.valueOf(anonymousCounter++), false);
                isContained = true;
            } else if (refName != null) {
                // Reference being an element, consider references as references to entity type.
                fieldType = new SoftTypeRef(this, refName.getTargetNamespace(), refName.getName(), true);
            } else {
                throw new NotImplementedException();
            }
        }
    }
    if (isContained) {
        ContainedTypeFieldMetadata containedField = new ContainedTypeFieldMetadata(containingType, isMany, isMandatory, fieldName, (ComplexTypeMetadata) fieldType, isReference, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
        containedField.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
        containedField.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
        containedField.setData(XSD_ELEMENT, element);
        containedField.setData(XSD_DOM_ELEMENT, element.getElement());
        containedField.setData(MIN_OCCURS, minOccurs);
        containedField.setData(MAX_OCCURS, maxOccurs);
        if (fieldType.getName().startsWith(ANONYMOUS_PREFIX)) {
            currentTypeStack.push((ComplexTypeMetadata) containedField.getType());
            {
                XmlSchemaWalker.walk(schemaType, this);
            }
            currentTypeStack.pop();
        }
        setLocalizedNames(containedField, state.getLocaleToLabel());
        setLocalizedDescriptions(containedField, state.getLocaleToDescription());
        return containedField;
    } else {
        FieldMetadata field = new SimpleTypeFieldMetadata(containingType, false, isMany, isMandatory, fieldName, fieldType, allowWriteUsers, hideUsers, workflowAccessRights, visibilityRule);
        field.setData(XSD_LINE_NUMBER, XSDParser.getStartLine(element.getElement()));
        field.setData(XSD_COLUMN_NUMBER, XSDParser.getStartColumn(element.getElement()));
        field.setData(XSD_ELEMENT, element);
        field.setData(XSD_DOM_ELEMENT, element.getElement());
        field.setData(MIN_OCCURS, minOccurs);
        field.setData(MAX_OCCURS, maxOccurs);
        setLocalizedNames(field, state.getLocaleToLabel());
        setLocalizedDescriptions(field, state.getLocaleToDescription());
        return field;
    }
}
Also used : NotImplementedException(org.apache.commons.lang.NotImplementedException) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XmlSchemaAnnotationProcessorState(org.talend.mdm.commmon.metadata.annotation.XmlSchemaAnnotationProcessorState) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) NotImplementedException(org.apache.commons.lang.NotImplementedException) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XmlSchemaAnnotationProcessor(org.talend.mdm.commmon.metadata.annotation.XmlSchemaAnnotationProcessor)

Example 12 with NotImplementedException

use of org.apache.commons.lang.NotImplementedException in project tmdm-common by Talend.

the class MetadataRepository method visitSimpleType.

@Override
public void visitSimpleType(XSDSimpleTypeDefinition type) {
    String typeName = type.getName();
    TypeMetadata typeMetadata = getNonInstantiableType(targetNamespace, typeName);
    if (typeMetadata == null) {
        typeMetadata = new SimpleTypeMetadata(targetNamespace, typeName);
    }
    List<TypeMetadata> superTypes = new LinkedList<TypeMetadata>();
    if (typeName == null) {
        // Anonymous simple type (expects this is a restriction of a simple type or fails).
        XSDSimpleTypeDefinition baseTypeDefinition = type.getBaseTypeDefinition();
        if (baseTypeDefinition != null) {
            typeName = baseTypeDefinition.getName();
        } else {
            throw new NotImplementedException("Support for " + type);
        }
    } else {
        // Simple type might inherit from other simple types (i.e. UUID from string).
        XSDSimpleTypeDefinition baseType = type.getBaseTypeDefinition();
        if (baseType != null && baseType.getName() != null) {
            superTypes.add(new SoftTypeRef(this, baseType.getTargetNamespace(), baseType.getName(), false));
            EList<XSDConstrainingFacet> facets = type.getFacetContents();
            for (XSDConstrainingFacet currentFacet : facets) {
                if (currentFacet instanceof XSDMaxLengthFacet) {
                    typeMetadata.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDMaxLengthFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDLengthFacet) {
                    typeMetadata.setData(MetadataRepository.DATA_MAX_LENGTH, String.valueOf(((XSDLengthFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDTotalDigitsFacet) {
                    // this is the totalDigits
                    typeMetadata.setData(MetadataRepository.DATA_TOTAL_DIGITS, String.valueOf(((XSDTotalDigitsFacet) currentFacet).getValue()));
                } else if (currentFacet instanceof XSDFractionDigitsFacet) {
                    // this is the fractionDigits
                    typeMetadata.setData(MetadataRepository.DATA_FRACTION_DIGITS, String.valueOf(((XSDFractionDigitsFacet) currentFacet).getValue()));
                } else if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Ignore simple type facet on type '" + typeName + "': " + currentFacet);
                }
            }
        }
    }
    if (getNonInstantiableType(targetNamespace, typeName) == null) {
        for (TypeMetadata superType : superTypes) {
            typeMetadata.addSuperType(superType);
        }
        addTypeMetadata(typeMetadata);
    }
}
Also used : XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) NotImplementedException(org.apache.commons.lang.NotImplementedException) LinkedList(java.util.LinkedList) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDConstrainingFacet(org.eclipse.xsd.XSDConstrainingFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet)

Example 13 with NotImplementedException

use of org.apache.commons.lang.NotImplementedException in project apex-core by apache.

the class ClassPathResolvers method createResolvers.

/**
 * Parse the resolver configuration
 * @param resolverConfig
 * @return
 */
public List<Resolver> createResolvers(String resolverConfig) {
    String[] specs = resolverConfig.split(",");
    List<Resolver> resolvers = new ArrayList<>(specs.length);
    for (String s : specs) {
        s = s.trim();
        String[] comps = s.split(":");
        if (comps.length == 0) {
            throw new IllegalArgumentException(String.format("Invalid resolver spec %s in %s", s, resolverConfig));
        }
        if (SCHEME_MANIFEST.equals(comps[0])) {
            if (comps.length < 2) {
                throw new IllegalArgumentException(String.format("Missing repository path in manifest resolver spec %s in %s", s, resolverConfig));
            }
            File baseDir = new File(comps[1]);
            resolvers.add(new ManifestResolver(baseDir));
        } else if (SCHEME_MVN.equals(comps[0])) {
            MavenResolver mvnr = new MavenResolver();
            if (comps.length > 1) {
                mvnr.userHome = comps[1];
            }
            resolvers.add(mvnr);
        } else {
            throw new NotImplementedException("Unknown resolver scheme " + comps[0]);
        }
    }
    return resolvers;
}
Also used : NotImplementedException(org.apache.commons.lang.NotImplementedException) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 14 with NotImplementedException

use of org.apache.commons.lang.NotImplementedException in project apex-core by apache.

the class StramAppLauncher method processLibJars.

private void processLibJars(String libjars, Set<URL> clUrls) throws Exception {
    for (String libjar : libjars.split(",")) {
        // if hadoop file system, copy from hadoop file system to local
        URI uri = new URI(libjar);
        String scheme = uri.getScheme();
        if (scheme == null) {
            // expand wildcards
            DirectoryScanner scanner = new DirectoryScanner();
            scanner.setIncludes(new String[] { libjar });
            scanner.scan();
            String[] files = scanner.getIncludedFiles();
            for (String file : files) {
                clUrls.add(new URL("file:" + file));
            }
        } else if (scheme.equals("file")) {
            clUrls.add(new URL(libjar));
        } else {
            if (fs != null) {
                Path path = new Path(libjar);
                File dependencyJarsDir = new File(StramClientUtils.getUserDTDirectory(), "dependencyJars");
                dependencyJarsDir.mkdirs();
                File localJarFile = new File(dependencyJarsDir, path.getName());
                fs.copyToLocalFile(path, new Path(localJarFile.getAbsolutePath()));
                clUrls.add(new URL("file:" + localJarFile.getAbsolutePath()));
            } else {
                throw new NotImplementedException("Jar file needs to be from Hadoop File System also in order for the dependency jars to be in Hadoop File System");
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) NotImplementedException(org.apache.commons.lang.NotImplementedException) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 15 with NotImplementedException

use of org.apache.commons.lang.NotImplementedException in project cogcomp-nlp by CogComp.

the class NETagPlain method tagData.

/**
 * Does this assume that init() has been called already?
 *
 * @param inputPath
 * @param outputPath
 * @throws Exception
 */
public static void tagData(String inputPath, String outputPath, String dataFormat, ParametersForLbjCode params) throws Exception {
    Data data;
    if (!dataFormat.equals("-plaintext")) {
        data = new Data(inputPath, inputPath, dataFormat, new String[] {}, new String[] {}, params);
    } else {
        // plaintext reading/writing.
        File f = new File(inputPath);
        Vector<String> inFiles = new Vector<>();
        Vector<String> outFiles = new Vector<>();
        if (f.isDirectory()) {
            String[] files = f.list();
            for (String file : files) if (!file.startsWith(".")) {
                inFiles.addElement(inputPath + File.separator + file);
                outFiles.addElement(outputPath + File.separator + file);
            }
        } else {
            inFiles.addElement(inputPath);
            outFiles.addElement(outputPath);
        }
        data = new Data();
        for (int fileId = 0; fileId < inFiles.size(); fileId++) {
            logger.debug("Tagging file: " + inFiles.elementAt(fileId));
            ArrayList<LinkedVector> sentences = PlainTextReader.parsePlainTextFile(inFiles.elementAt(fileId), params);
            NERDocument doc = new NERDocument(sentences, "consoleInput");
            data.documents.add(doc);
        }
    }
    ExpressiveFeaturesAnnotator.annotate(data, params);
    Decoder.annotateDataBIO(data, params);
    if (dataFormat.equals("-c")) {
        for (int docid = 0; docid < data.documents.size(); docid++) {
            List<String> res = new ArrayList<>();
            ArrayList<LinkedVector> sentences = data.documents.get(docid).sentences;
            for (LinkedVector vector : sentences) {
                for (int j = 0; j < vector.size(); j++) {
                    NEWord w = (NEWord) vector.get(j);
                    res.add(w.form + " " + w.neLabel + " " + w.neTypeLevel1);
                }
                res.add("");
            }
            LineIO.write(outputPath + "/" + docid + ".txt", res);
        }
    } else if (dataFormat.equals("-json")) {
        File inputfiles = new File(inputPath);
        List<TextAnnotation> tas = new ArrayList<>();
        for (String f : inputfiles.list()) {
            TextAnnotation ta = SerializationHelper.deserializeTextAnnotationFromFile(f, true);
            tas.add(ta);
        }
        TextAnnotationConverter.Data2TextAnnotation(data, tas);
        for (TextAnnotation ta : tas) {
            SerializationHelper.serializeTextAnnotationToFile(ta, outputPath + "/" + ta.getId(), true);
        }
    } else {
        throw new NotImplementedException("We do not yet support dataFormat of " + dataFormat + " yet.");
    }
}
Also used : LinkedVector(edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector) NotImplementedException(org.apache.commons.lang.NotImplementedException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TextAnnotation(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation) File(java.io.File) LinkedVector(edu.illinois.cs.cogcomp.lbjava.parse.LinkedVector) Vector(java.util.Vector)

Aggregations

NotImplementedException (org.apache.commons.lang.NotImplementedException)36 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Path (org.apache.hadoop.fs.Path)4 ASTNode (com.intellij.lang.ASTNode)3 IElementType (com.intellij.psi.tree.IElementType)3 File (java.io.File)3 Collection (java.util.Collection)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Entry (java.util.Map.Entry)3 NotNull (org.jetbrains.annotations.NotNull)3 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 TableName (org.apache.hadoop.hbase.TableName)2 DMLProgram (org.apache.sysml.parser.DMLProgram)2 XSDConstrainingFacet (org.eclipse.xsd.XSDConstrainingFacet)2