Inherit XSD namespace prefix - jaxb

I have a lot XSD which access each other.
Since I'm changing to JAXB I'm currently looking for a straightforward way to add namespaces to the xsds according to their folder structure.
My main issue at the moment is to add the namespace to the XSD itself, to the import in the accessing file and also to the prefix definition in the accessing file.
Here a small example (not quite real live)
User.xsd - targetNamespace="common.user"
Message.xsd - targetNamespace="common.message"
Email.xsd - targetNamespace="email" xmlns:user="common.user" xmlns:message="common.message"
import namespace="common.user" schemaLocation="./common/user.xsd"
import namespace="common.message" schemaLocation="./common/message.xsd"
When I now have a new Message.xsd schema I have to duplicate 90% of my xsd header.
I was creating a Namespace.xsd xmlns:user="common.user" xmlns:message="common.message" which is then included by Email.xsd. But accessing e.g. user:name did not work.
Is there a way to save the namespace-prefix definition in a central XSD-file so I do not have to define them in every single xsd?
Also, is there a way to not need to set the namespace in the import when it is already defines in the imported xsd as targetNamespace?

I think (not 100% sure though) that including into the schema A a schema B which imports another schema C will give you access to C in A.
However you will still need to declare the namespace prefix (like xmlns:user="common.user").
ps. Just a warning - never ever do chameleon schemas. It does not seem that you plan to, but i still wanted to warn.

Related

Why are Angular Component and Module class names for Entities prefixed with the application base name?

The generated Angular component names and module names are prefixed with the base application name specified when generating the code with JHipster as seen by the Entity Module imports shown below for a generated project.
In the following example from a generated entity.module.ts file, the entity module names have a prefix of "Gohomenotes" based I had specified a base application name of "gohomenotes" when I generated the code.
#NgModule({
imports: [
GohomenotesPersonModule,
GohomenotesStudentModule,
GohomenotesHomeRoomModule,
GohomenotesTeacherModule,
GohomenotesSchoolModule,
GohomenotesHostRequestModule,
GohomenotesGuestRequestModule,
GohomenotesEarlyPickupRequestModule,
GohomenotesTransportationChangeRequestModule,
GohomenotesFamilyModule,
GohomenotesFamilyMemberModule,
GohomenotesAddressModule,
GohomenotesPhoneNumberModule,
GohomenotesGoHomeNotesSettingsModule
However, the corresponding filenames do not include the base application name. This is not consistent with the Angular style guide and makes the code harder to read IMO.
Unless there is a practical reason that this is necessary, I'd prefer to not have the base application name on the component and module class names. Is there any harm if I remove the application base name from the module and component class names?
I asked this question on Gitter and got an answer from Shaheen Georgee #1in9ui5t...
Why are Angular Component and Module class names for Entities prefixed with the application base name?
"MyAppStudentModule" Rather than just "StudentModule" when I have an entity named "Student"?
Most likely to avoid potential naming conflicts with other modules in your Angular application. For example, let’s say you were working on a medical application and had a Test entity to signify some medical exam that your organization conducts; if you generated a Test entity (poor name I know), then generated test.module.ts would cause a naming conflict as there is already a module with that name.
I’m taking a guess here, I know from looking at Jhipster code in the past that there are black-listed terms.
Related: Name collision by module import in Angular 2 - is there a way to prevent it

Missing props on RowRendererParams

We're currently working on a table powered by React Virtualized and using TypeScript.
At the moment we're looking at making a custom row render.
We started off by looking at the implementation of the defaultRowRenderer.
We took that code and started modifying it to our needs, and we noticed that there are two props it expects that aren't defined in the #types/react-virtualised type definitions.
key, and onRowRightClick.
So we dug a bit deeper and had a look at the types.js which is in the same directory as defaultRowRenderer.js and found that babelPluginFlowReactPropTypes_proptype_RowRendererParams also doesn't define those props.
We then had a look at the Grid and List folders, and their types.js files do contain the key prop in babelPluginFlowReactPropTypes_proptype_RowRendererParams (List) and babelPluginFlowReactPropTypes_proptype_CellRendererParams (Grid).
Should key, and onRowRightClick be defined in Table/types.js.
And if so is the fact they are missing the reason that they're also missing in the TypeScript definitions?
Or am I miss-reading the entire lot? ;)
And if so is the fact they are missing the reason that they're also missing in the TypeScript definitions?
The TypeScript definitions aren't maintained by me so they may lag behind the actual project for no good reason.
As for why those props are missing from the Flow type in the git repo- probably just an oversight. The type isn't a strict object type so additional properties aren't treated as an error. We should add them into the type and fix it though.

Can i force a type to a json file?

recently i've been asked to implement config files for my system, config for each environment.
When i wanted to use the config i noticed that i dont have it typed, at least not in easy way..
So i created an index file which import and export the config adding an interface to it.
I wonder if i can add a type to my config (somehow) which will force the developers to stick to it and also provide us a type at compilation time.
Its like to have a config.ts file instead of config.json (maybe that what i should do?)
Thanks!
Yes you can - use json schema for this purpose.
To ensure your develpers have not messed up the data - use one of many available validators (i find this one to work pretty nice) to verify json object you read from config file.
Some IDE (vscode for example) support json schemas and can validate it on the fly.
You can have your config stored in *.ts file as exported const variable. Then after requiring it verify it with validator. Unfortunately this approach will not give you errors at compilation type.

Groovy - extensions structure

I'd like to extend String's asType method to handle LocalDateTime. I know how to override this method, however I've no idea where should I put it in project structure to work globally - for all strings in my project. Is it enough to put such extension wherever in the classpath? I know that there's a special convention for extensions (META-INF/services), how does it work for method overriding?
All documentation regarding this topic can be found here. And here exactly the relevant part can be found.
Module extension and module descriptor
For Groovy to be able to load your extension methods, you must declare
your extension helper classes. You must create a file named
org.codehaus.groovy.runtime.ExtensionModule into the META-INF/services
directory:
org.codehaus.groovy.runtime.ExtensionModule moduleName=Test module for
specifications moduleVersion=1.0-test
extensionClasses=support.MaxRetriesExtension
staticExtensionClasses=support.StaticStringExtension The module
descriptor requires 4 keys:
moduleName : the name of your module
moduleVersion: the version of your module. Note that version number is
only used to check that you don’t load the same module in two
different versions.
extensionClasses: the list of extension helper classes for instance
methods. You can provide several classes, given that they are comma
separated.
staticExtensionClasses: the list of extension helper classes for
static methods. You can provide several classes, given that they are
comma separated.
Note that it is not required for a module to define both static
helpers and instance helpers, and that you may add several classes to
a single module. You can also extend different classes in a single
module without problem. It is even possible to use different classes
in a single extension class, but it is recommended to group extension
methods into classes by feature set.
Module extension and classpath
It’s worth noting that you can’t use an extension which is compiled at
the same time as code using it. That means that to use an extension,
it has to be available on classpath, as compiled classes, before the
code using it gets compiled. Usually, this means that you can’t have
the test classes in the same source unit as the extension class
itself. Since in general, test sources are separated from normal
sources and executed in another step of the build, this is not an
issue.

How to tell the parser where to look for a local copy of xml.xsd?

I am creating an eclipse rcp application in which I am using SAXParser to parse an XML document. The "EventsDefinition.xsd" which I am using to validate the XML document has following import:
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="xml.xsd"/>
I keep the "EventsDefinition.xsd" & "xml.xsd" in the eclipse folder of the exported rcp product.
For accessing the "EventsDefinition.xsd", I use the following code which works.
URL fileURL = new URL(Platform.getInstallLocation().getURL() + "EventsDefinition.xsd");
File eventsDefinitionFile = new File(fileURL.getPath());
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", eventsDefinitionFile);
With this, the parser is able to access "EventsDefinition.xsd" but not the "xml.xsd" referenced by it, because it tries to find the xml.xsd relative to the directory from which the rcp application is executed.
Is there a similar way to tell the parser to find the "xml.xsd" at eclipse folder rather than in the present working directory?
I tried specifying schemaLocation="http://www.w3.org/2001/xml.xsd" in EventsDefinition.xsd, but it fails to read the schema. So I have to use the local copy of "xml.xsd" present at the exported product's eclipse folder.
Any suggestions will be extremely helpful.
I think that the problem is with the import declaration. First, although permitted, is not recommended to use "namespace" as a namespace prefix. Second, the problem arises form the fact that you use "http://www.w3.org/XML/1998/namespace" as namespace name, which is prohibited. Take a look here: http://www.w3.org/TR/REC-xml-names/#dt-prefix , precisely here:
The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace.
Try to rename the namespace name to something else (and the namespace prefix too). Hope it helps.

Resources