|
|
Re: specifying .xsd namespace inside XML file [message #667329 is a reply to message #667139] |
Thu, 28 April 2011 07:43 |
Andrew Miga Messages: 10 Registered: August 2009 |
Junior Member |
|
|
>I have no idea why folks would need a specialized helper...
I should have explained this in the original message. The XML Helpers simply add and remove capitalization of the first letter of elements to make the XML output prettier. The university where I work wanted to capitalize the first letter of elements to make the XML output prettier. Note the capitalization on elements Scenario, Step, Start, Refinement etc. below. Ecore does not do this capitalization and outputs all lower case. One XML Helper adds capitalization on output, another removes it on input loading. I inherited these functions and can't remove them without destroying compatibility.
You are correct in that most folks wouldn't need a helper but we are using them to add and remove capitalization.
<?xml version="1.0" encoding="ASCII"?>
<CSM xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" CSM:Root="file:/home/andrew/CSM/UMLActivity2CSM/resources/CSM.xsd ">
<Scenario id="ID000000" name="BuildingSurveillanceSystem">
<Step id="ID000002" name="cycleInit" predecessor="ID000001" successor="ID000003"/>
<Step id="ID000004" name="getOneImage" predecessor="ID000003" successor="ID000066">
<Refinement parent="ID000004" sub="ID000005"/>
</Step>
<Start id="ID000001" target="ID000002">
<ClosedWorkload externalDelay="1.0" population="1"/>
</Start>
The following is sample code from the input helper which removes capitalization for deserialization
public EStructuralFeature getFeature(EClass eClass,
String namespaceURI, String name, boolean isElement) {
name = shouldMakeFirstLetterLowerCase(name)?
makeFirstLetterLowerCase(name):
name;
// TODO Auto-generated method stub
return super.getFeature(eClass, namespaceURI, name, isElement);
}
private String makeFirstLetterLowerCase(String name){
String firstLetter = name.substring(0, 1);
firstLetter = firstLetter.toLowerCase();
return firstLetter + name.substring(1);
}
private boolean shouldMakeFirstLetterLowerCase(String name){
if ((name.equals("Step"))||
(name.equals("Scenario")) ||
(name.equals("PassiveResource"))||
(name.equals("Component"))||
(name.equals("ActiveResource"))||
....
(name.equals("OutBinding"))||
(name.equals("PerfValue"))
return true;
}
return false;
}
>Is the right resource factory registered to create your specialized resource?
There was no resource factory registered at all. I registered the appropriate factory and performed several other steps and it is now working.
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "csm", new CSMResourceFactoryImpl() );
resourceSet.getPackageRegistry().put( CSMPackage.eNS_URI, CSMPackage.eINSTANCE);
resourceSet.getResources().add( csmResource );
All of these steps were missing from the original code which may never have worked.
Thank you for your help.
|
|
|
Re: specifying .xsd namespace inside XML file [message #667359 is a reply to message #667329] |
Thu, 28 April 2011 09:50 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
Andrew,
Comments below.
Andrew Miga wrote:
>> I have no idea why folks would need a specialized helper...
>
> I should have explained this in the original message. The XML Helpers
> simply add and remove capitalization of the first letter of elements
> to make the XML output prettier.
Extended meta data annotations work nicely for that as well...
> The university where I work wanted to capitalize the first letter of
> elements to make the XML output prettier. Note the capitalization on
> elements Scenario, Step, Start, Refinement etc. below. Ecore does not
> do this capitalization and outputs all lower case.
Yes it uses the feature name by default but there are annotations you
can use to specify the XML name.
> One XML Helper adds capitalization on output, another removes it on
> input loading. I inherited these functions and can't remove them
> without destroying compatibility.
> You are correct in that most folks wouldn't need a helper but we are
> using them to add and remove capitalization.
>
> <?xml version="1.0" encoding="ASCII"?>
> <CSM xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> CSM:Root="file:/home/andrew/CSM/UMLActivity2CSM/resources/CSM.xsd ">
> <Scenario id="ID000000" name="BuildingSurveillanceSystem">
> <Step id="ID000002" name="cycleInit" predecessor="ID000001"
> successor="ID000003"/>
> <Step id="ID000004" name="getOneImage" predecessor="ID000003"
> successor="ID000066">
> <Refinement parent="ID000004" sub="ID000005"/>
> </Step>
> <Start id="ID000001" target="ID000002">
> <ClosedWorkload externalDelay="1.0" population="1"/>
> </Start>
>
>
> The following is sample code from the input helper which removes
> capitalization for deserialization
>
> public EStructuralFeature getFeature(EClass eClass,
> String namespaceURI, String name, boolean isElement) {
> name = shouldMakeFirstLetterLowerCase(name)?
> makeFirstLetterLowerCase(name):
> name;
> // TODO Auto-generated method stub
> return super.getFeature(eClass, namespaceURI, name, isElement);
> }
>
> private String makeFirstLetterLowerCase(String name){
> String firstLetter = name.substring(0, 1);
> firstLetter = firstLetter.toLowerCase();
> return firstLetter + name.substring(1);
> }
> private boolean shouldMakeFirstLetterLowerCase(String name){
> if ((name.equals("Step"))||
> (name.equals("Scenario")) ||
> (name.equals("PassiveResource"))||
> (name.equals("Component"))||
> (name.equals("ActiveResource"))||
> ....
>
> (name.equals("OutBinding"))||
> (name.equals("PerfValue")) return true;
> }
> return false;
> }
>
>> Is the right resource factory registered to create your specialized
>> resource?
>
> There was no resource factory registered at all. I registered the
> appropriate factory and performed several other steps and it is now
> working.
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto
> ryMap().put( "csm", new CSMResourceFactoryImpl() );
> resourceSet.getPackageRegistry().put( CSMPackage.eNS_URI,
> CSMPackage.eINSTANCE);
> resourceSet.getResources().add( csmResource );
>
>
> All of these steps were missing from the original code which may never
> have worked.
>
> Thank you for your help.
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03238 seconds