ElementFactoryImpl implements ElementFactory { public Element createElement(org.w3c.dom.Element xmlElement) throws ConstraintViolationException { String namespaceUri = xmlElement.getNamespaceURI(); if (Schemas.XLIFF_12_NAMESPACE.equals(namespaceUri)) { return createXliffElement(xmlElement); } return createNonXliffElement(xmlElement); } private  ElementFactoryImpl(); static ElementFactoryImpl getInstance(); Xliff createXliff(Version version, List<File> files); Xliff createXliff(Version version, File file); File createFile(Original original, SourceLanguage sourceLanguage,
			DataType dataType, Body body); Header createHeader(); Skl createSkl(Skl.Child part); InternalFile createInternalFile(Text embeddedFile); ExternalFile createExternalFile(Href href); Glossary createGlossary(Glossary.Child part); Reference createReference(Child child); Note createNote(Text note); PhaseGroup createPhaseGroup(List<Phase> phases); Phase createPhase(PhaseName phaseName, ProcessName processName); Tool createTool(ToolId toolId, ToolName toolName); CountGroup createCountGroup(Name name, List<Count> counts); Count createCount(CountType countType, Text number); Count createCount(CountType countType, int number); ContextGroup createContextGroup(List<Context> contexts); Context createContext(ContextType contextType, Text content); com.sap.mlt.xliff12.api.element.namedgroup.PropGroup createPropGroup(
			List<com.sap.mlt.xliff12.api.element.namedgroup.Prop> props); com.sap.mlt.xliff12.api.element.namedgroup.Prop createProp(
			com.sap.mlt.xliff12.api.attribute.PropType propType, Text content); Body createBody(List<? extends StructuralUnit> structuralUnits); Group createGroup(List<? extends StructuralUnit> structuralUnits); TransUnit createTransUnit(Id id, Source source); Source createSource(List<? extends TextFragment> textFragments); Source createSource(String text); Target createTarget(List<? extends TextFragment> textFragments); Target createTarget(String text); AltTrans createAltTrans(Target target); BinUnit createBinUnit(Id id, MimeType mimeType, BinSource binSource); BinSource createBinSource(BinSource.Child child); BinTarget createBinTarget(BinTarget.Child child); SegSource createSegSource(List<? extends TextFragment> textFragments); G createG(Id id, List<? extends TextFragment> content); X createX(Id id); Bx createBx(Id id); Ex createEx(Id id); Ph createPh(Id id, List<? extends CodeFragment> content); Bpt createBpt(Id id, List<? extends CodeFragment> content); Ept createEpt(Id id, List<? extends CodeFragment> content); It createIt(Id id, Pos pos, List<? extends CodeFragment> content); Sub createSub(List<? extends TextFragment> content); Mrk createMrk(Mtype mtype, List<? extends TextFragment> content); NonXliffElement createNonXliffElement(org.w3c.dom.Element xmlElement); NonXliffElement createNonXliffElement(String namespaceUri,
			String name, Collection<? extends Attribute> attributes,
			List<? extends Node> children); NonXliffElement createNonXliffElement(String namespaceUri,
			String prefix, String name,
			Collection<? extends Attribute> attributes,
			List<? extends Node> children); Element createElement(org.w3c.dom.Element xmlElement);  }
@Test public void testCreateElement() throws ConstraintViolationException { ElementFactoryImpl factory = ElementFactoryImpl.getInstance(); Document doc = Utils.createDocument(); org.w3c.dom.Element elem; Element xliffElem; elem = doc.createElementNS(XLIFF_12_NAMESPACE, "xliff"); elem.setAttributeNS(null, "version", "1.2"); elem.appendChild(createDefaultFile().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new XliffImpl(new VersionImpl(Version.Value.V1_2), createDefaultFiles()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "file"); elem.setAttributeNS(null, "original", "abc"); elem.setAttributeNS(null, "source-language", "en-US"); elem.setAttributeNS(null, "datatype", "x-xyz"); elem.appendChild(createDefaultBody().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new FileImpl(new OriginalImpl("abc"), new SourceLanguageImpl("en-US"), new DataTypeImpl("xyz"), createDefaultBody()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "header"); xliffElem = factory.createElement(elem); assertEquals(new HeaderImpl(), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "skl"); elem.appendChild(createDefaultInternalFile().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new SklImpl(createDefaultInternalFile()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "internal-file"); elem.setTextContent("intf"); xliffElem = factory.createElement(elem); assertEquals(new InternalFileImpl(new TextImpl("intf")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "external-file"); elem.setAttributeNS(null, "href", "http: xliffElem = factory.createElement(elem); assertEquals(new ExternalFileImpl(new HrefImpl("http: xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "glossary"); elem.appendChild(createDefaultInternalFile().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new GlossaryImpl(createDefaultInternalFile()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "reference"); elem.appendChild(createDefaultInternalFile().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new ReferenceImpl(createDefaultInternalFile()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "note"); elem.setTextContent("textnote"); xliffElem = factory.createElement(elem); assertEquals(new NoteImpl(new TextImpl("textnote")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "phase-group"); elem.appendChild(createDefaultPhase().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new PhaseGroupImpl(createDefaultPhases()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "phase"); elem.setAttributeNS(null, "phase-name", "pn"); elem.setAttributeNS(null, "process-name", "procn"); xliffElem = factory.createElement(elem); assertEquals(new PhaseImpl(new PhaseNameImpl("pn"), new ProcessNameImpl("procn")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "tool"); elem.setAttributeNS(null, "tool-id", "ti"); elem.setAttributeNS(null, "tool-name", "tn"); xliffElem = factory.createElement(elem); assertEquals( new ToolImpl(new ToolIdImpl("ti"), new ToolNameImpl("tn")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "count-group"); elem.setAttributeNS(null, "name", "cgn"); elem.appendChild(createDefaultCount().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new CountGroupImpl(new NameImpl("cgn"), createDefaultCounts()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "count"); elem.setAttributeNS(null, "count-type", "total"); elem.setTextContent("3"); xliffElem = factory.createElement(elem); assertEquals(new CountImpl(new CountTypeImpl(CountType.Value.TOTAL), new TextImpl("3")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "context-group"); elem.appendChild(createDefaultContext().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new ContextGroupImpl(createDefaultContexts()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "context"); elem.setAttributeNS(null, "context-type", "record"); elem.setTextContent("ctc"); xliffElem = factory.createElement(elem); assertEquals(new ContextImpl(new ContextTypeImpl( ContextType.Value.RECORD), new TextImpl("ctc")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "prop-group"); elem.appendChild(createDefaultProp().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new PropGroupImpl(createDefaultProps()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "prop"); elem.setAttributeNS(null, "prop-type", "abc"); elem.setTextContent("ptc"); xliffElem = factory.createElement(elem); assertEquals( new PropImpl(new PropTypeImpl("abc"), new TextImpl("ptc")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "body"); xliffElem = factory.createElement(elem); assertEquals(new BodyImpl(new ArrayList<StructuralUnit>()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "group"); xliffElem = factory.createElement(elem); assertEquals(new GroupImpl(new ArrayList<StructuralUnit>()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "trans-unit"); elem.setAttributeNS(null, "id", "1"); elem.appendChild(createDefaultSource().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new TransUnitImpl(new IdImpl("1"), createDefaultSource()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "source"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals(new SourceImpl(createDefaultTextFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "target"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals(new TargetImpl(createDefaultTextFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "alt-trans"); elem.appendChild(createDefaultTarget().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new AltTransImpl(createDefaultTarget()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "bin-unit"); elem.setAttributeNS(null, "id", "1"); elem.setAttributeNS(null, "mime-type", "text/plain"); elem.appendChild(createDefaultBinSource().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new BinUnitImpl(new IdImpl("1"), new MimeTypeImpl( "text/plain"), createDefaultBinSource()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "bin-source"); elem.appendChild(createDefaultInternalFile().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new BinSourceImpl(createDefaultInternalFile()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "bin-target"); elem.appendChild(createDefaultInternalFile().asXmlNode(doc)); xliffElem = factory.createElement(elem); assertEquals(new BinTargetImpl(createDefaultInternalFile()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "seg-source"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals(new SegSourceImpl(createDefaultTextFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "g"); elem.setAttributeNS(null, "id", "1"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals(new GImpl(new IdImpl("1"), createDefaultTextFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "x"); elem.setAttributeNS(null, "id", "1"); xliffElem = factory.createElement(elem); assertEquals(new XImpl(new IdImpl("1")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "bx"); elem.setAttributeNS(null, "id", "1"); xliffElem = factory.createElement(elem); assertEquals(new BxImpl(new IdImpl("1")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "ex"); elem.setAttributeNS(null, "id", "1"); xliffElem = factory.createElement(elem); assertEquals(new ExImpl(new IdImpl("1")), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "ph"); elem.setAttributeNS(null, "id", "1"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals(new PhImpl(new IdImpl("1"), createDefaultCodeFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "bpt"); elem.setAttributeNS(null, "id", "1"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals( new BptImpl(new IdImpl("1"), createDefaultCodeFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "ept"); elem.setAttributeNS(null, "id", "1"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals( new EptImpl(new IdImpl("1"), createDefaultCodeFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "it"); elem.setAttributeNS(null, "id", "1"); elem.setAttributeNS(null, "pos", "open"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals(new ItImpl(new IdImpl("1"), new PosImpl(Pos.Value.OPEN), createDefaultCodeFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "sub"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals(new SubImpl(createDefaultTextFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "mrk"); elem.setAttributeNS(null, "mtype", "formula"); elem.setTextContent("text"); xliffElem = factory.createElement(elem); assertEquals(new MrkImpl(new MtypeImpl(Mtype.Value.FORMULA), createDefaultTextFragments()), xliffElem); elem = doc.createElementNS(XLIFF_12_NAMESPACE, "invalid"); try { factory.createElement(elem); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } }