Get the XSD Schema object for the UBLTR document type of the passed
implementation class.

@param aImplClass
The implementation class of any UBLTR document type. May be
<code>null</code>.
@return <code>null</code> if no such UBLTR document type exists.
548711
@Nullable
  public static Schema getSchemaOfImplementationClass (@Nullable final Class <?> aImplClass)
  {
    final EUBLTRDocumentType eDocType = getDocumentTypeOfImplementationClass (aImplClass);
    return eDocType == null ? null : eDocType.getSchema ();
  }
510002
@SuppressWarnings("unchecked")
	static <E, M extends BinderMapper<E>> M getMapper(Class<E> cls) {
		M mapper = (M) OBJECT_MAPPERS.get(cls);
		if (mapper == null) {
			// The only way the mapper wouldn't already be loaded into
			// OBJECT_MAPPERS is if it was compiled separately, but let's handle
			// it anyway
			String beanClassName = cls.getName();
			String mapperClassName = cls.getName() + KriptonBinder.MAPPER_CLASS_SUFFIX;
			try {
				Class<E> mapperClass = (Class<E>) Class.forName(mapperClassName);
				mapper = (M) mapperClass.newInstance();
				// mapper.
				OBJECT_MAPPERS.put(cls, mapper);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
				throw new KriptonRuntimeException(String.format("Class '%s' does not exist. Does '%s' have @BindType annotation?", mapperClassName, beanClassName));
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return mapper;
	}
178156
public static synchronized void initializeDXF_SCHEMA( CoordinateReferenceSystem crs ) {
        if (DXF_POINTSCHEMA != null && DXF_POINTSCHEMA.getAttributeCount() != 0)
            return;

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("dxfpointfile");
        b.setCRS(crs);
        b.add("the_geom", Point.class);
        b.add("LAYER", String.class);
        b.add("LTYPE", String.class);
        b.add("ELEVATION", Double.class);
        b.add("THICKNESS", Double.class);
        b.add("COLOR", Integer.class);
        b.add("TEXT", String.class);
        b.add("TEXT_HEIGHT", Double.class);
        b.add("TEXT_STYLE", String.class);
        DXF_POINTSCHEMA = b.buildFeatureType();

        b = new SimpleFeatureTypeBuilder();
        b.setName("dxflinefile");
        b.setCRS(crs);
        b.add("the_geom", LineString.class);
        b.add("LAYER", String.class);
        b.add("LTYPE", String.class);
        b.add("ELEVATION", Double.class);
        b.add("THICKNESS", Double.class);
        b.add("COLOR", Integer.class);
        b.add("TEXT", String.class);
        b.add("TEXT_HEIGHT", Double.class);
        b.add("TEXT_STYLE", String.class);
        DXF_LINESCHEMA = b.buildFeatureType();

        b = new SimpleFeatureTypeBuilder();
        b.setName("dxfpolygonfile");
        b.setCRS(crs);
        b.add("the_geom", Polygon.class);
        b.add("LAYER", String.class);
        b.add("LTYPE", String.class);
        b.add("ELEVATION", Double.class);
        b.add("THICKNESS", Double.class);
        b.add("COLOR", Integer.class);
        b.add("TEXT", String.class);
        b.add("TEXT_HEIGHT", Double.class);
        b.add("TEXT_STYLE", String.class);
        DXF_POLYGONSCHEMA = b.buildFeatureType();

    }
1016270
public static Index generateXsl(SetupOptions opts) throws Exception {
        Index masterIndex = new Index();

        // Create CTL validator
        SchemaFactory sf = SchemaFactory
                .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema ctl_schema = sf.newSchema(new StreamSource(Misc
                .getResourceURL("com/occamlab/te/schemas/ctl.xsd")));
        Validator ctl_validator = ctl_schema.newValidator();
        CtlErrorHandler validation_eh = new CtlErrorHandler();
        ctl_validator.setErrorHandler(validation_eh);

        // Create a transformer to generate executable scripts from CTL sources
        Processor processor = new Processor(false);
        processor.setConfigurationProperty(FeatureKeys.LINE_NUMBERING,
                Boolean.TRUE);
        XsltCompiler generatorCompiler = processor.newXsltCompiler();
        XsltExecutable generatorXsltExecutable = generatorCompiler.compile(
                new StreamSource(Misc.getResourceURL("com/occamlab/te/generate_xsl.xsl")));
        XsltTransformer generatorTransformer = generatorXsltExecutable.load();

        // Create a list of CTL sources (may be files or dirs)
        ArrayList<File> sources = new ArrayList<File>();
        File f = Misc.getResourceAsFile("com/occamlab/te/scripts/parsers.ctl");
        if (f.exists()) {
            sources.add(f.getParentFile());
        }
        sources.addAll(opts.getSources());

        // Create a list of source CTL files only (no dirs),
        // and a corresponding list containing a working dir for each file
        ArrayList<File> sourceFiles = new ArrayList<File>();
        ArrayList<File> workDirs = new ArrayList<File>();
        Iterator<File> it = sources.iterator();
        while (it.hasNext()) {
            File source = it.next();
            LOGR.log(Level.FINE, "Processing CTL source files in {0}",
                    source.getAbsolutePath());
            String encodedName = createEncodedName(source);
            File workingDir = new File(opts.getWorkDir(), encodedName);
            if (!workingDir.exists() && !workingDir.mkdir()) {
                LOGR.log(Level.WARNING,
                        "Unable to create working directory at {0}",
                        workingDir.getAbsolutePath());
            }
            if (source.isDirectory()) {
                String[] children = source.list();
                for (int i = 0; i < children.length; i++) {
                    // Finds all .ctl and .xml files in the directory to use
                    String lowerName = children[i].toLowerCase();
                    if (lowerName.endsWith(".ctl")
                            || lowerName.endsWith(".xml")) {
                        File file = new File(source, children[i]);
                        if (file.isFile()) {
                            sourceFiles.add(file);
                            String basename = children[i].substring(0,
                                    children[i].length() - 4);
                            File subdir = new File(workingDir, basename);
                            subdir.mkdir();
                            workDirs.add(subdir);
                        }
                    }
                }
            } else {
                sourceFiles.add(source);
                workDirs.add(workingDir);
            }
        }

        // resolve xinclude elements but omit xml:base attributes
        SAXParser parser = XMLParserUtils.createXIncludeAwareSAXParser(false);

        File generatorStylesheet = Misc.getResourceAsFile("com/occamlab/te/generate_xsl.xsl");
        
        // Process each CTL source file
        for (int i = 0; i < sourceFiles.size(); i++) {
            File sourceFile = sourceFiles.get(i);
            File workingDir = workDirs.get(i);

            // Read previous index for this file (if any), and determine whether
            // the index and xsl need to be regenerated
            File indexFile = new File(workingDir, "index.xml");
            Index index = null;
            boolean regenerate = true;
            
            if (generatorStylesheet == null) {
                //generatorStylesheet couldn't be found as a file (it was loaded from classpath jar)                
                regenerate = true;
            } else if (indexFile.isFile()) {
                try {
                    if (indexFile.lastModified() > generatorStylesheet
                            .lastModified()) {
                        index = new Index(indexFile);
                        regenerate = index.outOfDate();
                    }
                } catch (Exception e) {
                    // If there was an exception reading the index file, it is
                    // likely corrupt. Regenerate it.
                    regenerate = true;
                }
            }

            if (regenerate) {
                // Validate the source CTL file
                boolean validationErrors = false;
                if (opts.isValidate()) {
                    int old_count = validation_eh.getErrorCount();
                    LOGR.log(Level.CONFIG, "Validating " + sourceFile);
                    ctl_validator.validate(new StreamSource(sourceFile));
                    validationErrors = (validation_eh.getErrorCount() > old_count);
                }

                if (!validationErrors) {
                    // Clean up the working directory
                    Misc.deleteDirContents(workingDir);

                    InputSource input = new InputSource(new FileInputStream(
                            sourceFile));
                    input.setSystemId(sourceFile.toURI().toString());
                    // Fortify Mods to prevent External Entity Injection
                    XMLReader reader = parser.getXMLReader();
                    reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
                    Source ctlSource = new SAXSource(reader, input);
                    // Source ctlSource = new SAXSource(parser.getXMLReader(),input);
                    // End Fortify Mods
                    // Run the generator transformation. Output is an index file
                    // and is saved to disk. The generator also creates XSL
                    // template files in the working dir.
                    generatorTransformer.setSource(ctlSource);
                    Serializer generatorSerializer = new Serializer();
                    generatorSerializer.setOutputFile(indexFile);
                    generatorTransformer.setDestination(generatorSerializer);
                    XdmAtomicValue av = new XdmAtomicValue(
                            workingDir.getAbsolutePath());
                    generatorTransformer.setParameter(new QName("outdir"), av);
                    generatorTransformer.transform();

                    // Read the generated index
                    index = new Index(indexFile);
                }
            }
            // Add new index entries to the master index
            masterIndex.add(index);
        }

        // If there were any validation errors, display them and throw an
        // exception
        int error_count = validation_eh.getErrorCount();
        if (error_count > 0) {
            String msg = error_count + " validation error"
                    + (error_count == 1 ? "" : "s");
            int warning_count = validation_eh.getWarningCount();
            if (warning_count > 0) {
                msg += " and " + warning_count + " warning"
                        + (warning_count == 1 ? "" : "s");
            }
            msg += " detected.";
            // appLogger.severe(msg);
            throw new Exception(msg);
        }

        return masterIndex;
    }
464356
private XmlClass findXmlClass(Class<?> aClass){
		for (XmlClass xmlClass : xmlJmapper.classes) 
			if(xmlClass.name.equals(aClass.getName())) return xmlClass;
		return null;
	}
1118501
static <T> HasSchema<T> getSchemaWrapper(Class<T> typeClass,
            IdStrategy strategy)
    {
        return strategy.getSchemaWrapper(typeClass, true);
    }
1197962
@SuppressWarnings({"rawtypes"})
    private Map.Entry getMapEntry(XmlNode node) {
        String keyName = node.getName();
        Object value = null;
        XmlMapEntry xmlMapEntry = this.mapSpecification.get(keyName);
        switch (node.getType()) {
            case XmlNode.ATTRIBUTE_NODE:
                value = node.getValue();
                break;
            case XmlNode.ELEMENT_NODE: {
                if (xmlMapEntry == null) {
                    value = new XmlNodeArray(node.getChildren());
                } else {
                    XmlMapFacet valueFacet = xmlMapEntry.getValue();
                    switch (valueFacet.getType()) {
                        case ELEMENT:
                            value = keyName;
                            break;
                        case CONTENT: {
                            List<XmlNode> nodeList = node.getChildren();
                            if (nodeList.size() > 0) {
                                value = new XmlNodeArray(nodeList);
                            }
                        }
                            break;
                        case ATTRIBUTE: {
                            Map<String, XmlNode> attributes = node.getAttributes();
                            XmlNode attribute = attributes.get(valueFacet.getName());
                            if (attribute != null) {
                                value = attribute.getValue();
                            } else {
                            }
                        }
                            break;
                        default:
                            throw new IllegalStateException();
                    }
                    XmlMapFacet keyFacet = xmlMapEntry.getKey();
                    switch (keyFacet.getType()) {
                        case ELEMENT:
                            // keyName is already set
                            break;
                        case CONTENT: {
                            List<XmlNode> nodeList = node.getChildren();
                            if (nodeList.size() > 0) {
                                keyName = getStringValue((XmlNode) nodeList.get(0));
                            } else {
                                keyName = null;
                            }
                        }
                            break;
                        case ATTRIBUTE: {
                            Map<String, XmlNode> attributes = node.getAttributes();
                            XmlNode attribute = attributes.get(keyFacet.getName());
                            if (attribute != null) {
                                keyName = attribute.getValue();
                            } else {
                                keyName = null;
                            }
                            break;
                        }
                        default:
                            throw new IllegalStateException();
                    }
                }
            }
        }
        if (keyName == null) {
            return null;
        } else {
            final Object _key = keyName;
            final Object _value = value;
            return new Map.Entry() {

                @Override
                public Object getKey() {
                    return _key;
                }

                @Override
                public Object getValue() {
                    return _value;
                }

                @Override
                public Object setValue(Object object) {
                    return null;
                }

            };
        }
    }
1248320
public String getSchema(Class<?> clazz)
	{
		if (clazz == Integer.class || clazz == Integer.TYPE)
		{
			return "integer [" + Integer.MIN_VALUE + " to " + Integer.MAX_VALUE + "]";
		}
		else if (clazz == Long.class || clazz == Long.TYPE)
		{
			return "long [" + Long.MIN_VALUE + " to " + Long.MAX_VALUE + "]";
		}
		else if (clazz == Double.class || clazz == Double.TYPE)
		{
			return "double [" + Double.MIN_VALUE + " to " + Double.MAX_VALUE + "]";
		}
		else if (clazz == Boolean.class || clazz == Boolean.TYPE)
		{
			return "boolean [true, false]";
		}
		else if (clazz == Void.class)
		{
			return "void";
		}
		else if (clazz == Byte[].class || clazz == byte[].class)
		{
			return "binary stream";
		}
		else if (clazz.isEnum())
		{
			return "enum " + Arrays.asList(clazz.getEnumConstants());
		}
		else if (clazz.isAnnotationPresent(XmlRootElement.class))
		{
			try
			{
				final JAXBSerialiser serialiser = JAXBSerialiser.getMoxy(clazz);

				return generate(serialiser);
			}
			catch (Exception e)
			{
				// Ignore
				return "error generating schema for " + clazz + ": " + e.getMessage();
			}
		}
		else if (clazz.isAnnotationPresent(XmlType.class) || clazz.isAnnotationPresent(XmlEnum.class))
		{
			// Class generated by JAXB XSD To Java (as a result we have to emit the entire schema rather than being able to provide a specific sub-schema for the type in question because XmlRootElement is not specified)
			try
			{
				final JAXBSerialiser serialiser = JAXBSerialiser.getMoxy(clazz.getPackage().getName());

				return generate(serialiser);
			}
			catch (Exception e)
			{
				// Ignore
				return "error generating schema for XSD-To-Java package schema for class " + clazz + ": " + e.getMessage();
			}
		}
		else
		{
			return clazz.toString();
		}
	}
1273959
@Nullable
  public IURLProtocol getProtocol (@Nullable final ISimpleURL aURL)
  {
    return aURL == null ? null : getProtocol (aURL.getPath ());
  }
825965
@Override
    public <K, V> MapAttribute<? super X, K, V> getMap(String paramName, Class<K> keyClazz, Class<V> valueClazz)
    {
        PluralAttribute<X, ?, ?> declaredAttrib = getDeclaredPluralAttribute(paramName);

        if (onCheckMapAttribute(declaredAttrib, valueClazz))
        {
            if (valueClazz != null && valueClazz.equals(((MapAttribute<X, K, V>) declaredAttrib).getKeyJavaType()))
            {
                return (MapAttribute<X, K, V>) declaredAttrib;

            }
        }

        PluralAttribute<? super X, ?, ?> superAttrib = getPluralAttriute(paramName);

        if (onCheckMapAttribute(superAttrib, valueClazz))
        {
            if (valueClazz != null && valueClazz.equals(((MapAttribute<? super X, K, V>) superAttrib).getKeyJavaType()))
            {
                return (MapAttribute<? super X, K, V>) superAttrib;

            }
        }

        throw new IllegalArgumentException(
                "attribute of the given name and type is not present in the managed MapAttribute type, for name:"
                        + paramName + " , value type:" + valueClazz + "key tpye:" + keyClazz);
    }
572660
protected <T> Schema<T> newSchema(Class<T> typeClass)
    {
        // check if this is part of a group
        if(primaryGroup != null)
        {
            // only pojos created by runtime schema support groups
            final Schema<T> s = primaryGroup.getSchemaWrapper(
                    typeClass, true).getSchema();
            if(s instanceof RuntimeSchema)
            {
                final RuntimeSchema<T> rs = (RuntimeSchema<T>)s;
                
                final ArrayList<Field<T>> fields = new ArrayList<MappedSchema.Field<T>>(
                        rs.fields.length);
                
                for(Field<T> f : rs.fields)
                {
                    final int groupFilter = f.groupFilter;
                    if(groupFilter != 0)
                    {
                        final int set; // set for exclusion
                        if(groupFilter > 0)
                        {
                            // inclusion
                            set = ~groupFilter & 0x7FFFFFFF;
                        }
                        else
                        {
                            // exclusion
                            set = -groupFilter;
                        }
                        
                        if(0 != (groupId & set))
                        {
                            // this field is excluded on the current group id
                            continue;
                        }
                    }
                    
                    fields.add(f);
                }
                
                final int size = fields.size();
                if(size == rs.fields.length)
                {
                    // nothing is excluded
                    return rs;
                }
                
                if(size == 0)
                {
                    throw new RuntimeException("All fields were excluded for " + 
                            rs.messageFullName() + " on group " + groupId);
                }
                
                return new RuntimeSchema<T>(typeClass, fields, 
                        // the last field
                        fields.get(size-1).number, rs.instantiator);
            }
            
            return s;
        }

        return RuntimeSchema.createFrom(typeClass, this);
    }
842057
@SneakyThrows
    public <T extends SAMLObject> T newSamlObject(final Class<T> objectType) {
        val qName = getSamlObjectQName(objectType);
        val builder = (SAMLObjectBuilder<T>)
            XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(qName);
        if (builder == null) {
            throw new IllegalStateException("No SAML object builder is registered for class " + objectType.getName());
        }
        return objectType.cast(builder.buildObject(qName));
    }
920169
private ImmutableList<TargetAtom> getMappingTripleAtoms(TriplesMap tm) throws Exception {
		//the body to return
		ImmutableList.Builder<TargetAtom> bodyBuilder = ImmutableList.builder();
		
		//get subject
		ImmutableTerm subjectAtom = r2rmlParser.getSubjectAtom(tm);
		
		//get any class predicates, construct atom Class(subject), add to body
		List<ImmutableFunctionalTerm> classPredicates = r2rmlParser.getClassPredicates();
		for (ImmutableFunctionalTerm classPred : classPredicates) {
			ImmutableTerm predFunction = termFactory.getImmutableUriTemplate(termFactory.getConstantLiteral(RDF.TYPE.toString())); ;
			bodyBuilder.add(targetAtomFactory.getTripleTargetAtom(subjectAtom, predFunction, classPred));   // objectAtom
		}		

		for (PredicateObjectMap pom : tm.getPredicateObjectMaps()) {
			//for each predicate object map

			//predicates that contain a variable are separately treated
			List<ImmutableFunctionalTerm> bodyURIPredicates = r2rmlParser.getBodyURIPredicates(pom);
			
			//get object atom
			ImmutableTerm objectAtom = r2rmlParser.getObjectAtom(pom);
			
			if (objectAtom == null) {
				// skip, object is a join
				continue;
			}

			
			//treat predicates
			for (ImmutableFunctionalTerm predFunction : bodyURIPredicates) {

				bodyBuilder.add(targetAtomFactory.getTripleTargetAtom(subjectAtom, predFunction, objectAtom));   // objectAtom
			}
		}
		return bodyBuilder.build();
	}
102004
private byte[] getSchemaBytes() {

        StringBuffer schema = new StringBuffer(512);
        schema.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        schema.append("<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">");
        Iterator<I_CmsXmlSchemaType> i = m_registeredTypes.values().iterator();
        while (i.hasNext()) {
            I_CmsXmlSchemaType type = i.next();
            schema.append(type.getSchemaDefinition());
        }
        schema.append("</xsd:schema>");
        String schemaStr = schema.toString();

        try {
            // pretty print the XML schema
            // this helps in debugging the auto-generated schema includes
            // since it makes them more human-readable
            Document doc = CmsXmlUtils.unmarshalHelper(schemaStr, null);
            schemaStr = CmsXmlUtils.marshal(doc, CmsEncoder.ENCODING_UTF_8);
        } catch (CmsXmlException e) {
            // should not ever happen
            LOG.error(Messages.get().getBundle().key(Messages.LOG_PRETTY_PRINT_SCHEMA_BYTES_ERROR_0), e);
        }
        if (LOG.isInfoEnabled()) {
            LOG.info(
                Messages.get().getBundle().key(
                    Messages.LOG_XML_TYPE_DEFINITION_XSD_2,
                    CmsXmlContentDefinition.XSD_INCLUDE_OPENCMS,
                    schemaStr));
        }
        try {
            return schemaStr.getBytes(CmsEncoder.ENCODING_UTF_8);
        } catch (UnsupportedEncodingException e) {
            // should not happen since the default encoding of UTF-8 is always valid
            LOG.error(Messages.get().getBundle().key(Messages.LOG_CONVERTING_SCHEMA_BYTES_ERROR_0), e);
        }
        return null;
    }
501480
@Nullable
  protected byte [] getBoundary (@Nonnull final String sContentType)
  {
    // Parameter parser can handle null input
    final ICommonsMap <String, String> aParams = new ParameterParser ().setLowerCaseNames (true)
                                                                       .parse (sContentType, new char [] { ';', ',' });
    final String sBoundaryStr = aParams.get ("boundary");
    if (sBoundaryStr == null)
      return null;
    return sBoundaryStr.getBytes (StandardCharsets.ISO_8859_1);
  }
239690
@Override
    public MapAttribute<? super X, ?, ?> getMap(String paramName)
    {
        PluralAttribute<? super X, ?, ?> declaredAttrib = getDeclaredPluralAttribute(paramName);

        if (isMapAttribute(declaredAttrib))
        {
            return (MapAttribute<X, ?, ?>) declaredAttrib;
        }

        declaredAttrib = getPluralAttriute(paramName);

        if (isMapAttribute(declaredAttrib))
        {
            return (MapAttribute<X, ?, ?>) declaredAttrib;
        }

        throw new IllegalArgumentException(
                "attribute of the given name and type is not present in the managed type, for name:" + paramName);
    }
1309450
@Override
	protected String getURIFragmentRootSegment(EObject eObject) {
		if (unloadingContents == null) {
			IParseResult parseResult = getParseResult();
			if (parseResult != null && eObject == parseResult.getRootASTElement()) {
				return "0"; 
			}
		}
		return super.getURIFragmentRootSegment(eObject);
	}