+ protected void prepareDataModel() {
+ // importing node def on remote si currently not supported
+ if (isRemote())
+ return;
+
+ Session session = null;
+ try {
+ session = login();
+ // register namespaces
+ if (namespaces.size() > 0) {
+ NamespaceHelper namespaceHelper = new NamespaceHelper(session);
+ namespaceHelper.registerNamespaces(namespaces);
+ }
+ // load CND files from classpath or as URL
+ for (String resUrl : cndFiles) {
+ boolean classpath;
+ // normalize URL
+ if (resUrl.startsWith("classpath:")) {
+ resUrl = resUrl.substring("classpath:".length());
+ classpath = true;
+ } else if (resUrl.indexOf(':') < 0) {
+ if (!resUrl.startsWith("/")) {
+ resUrl = "/" + resUrl;
+ log.warn("Classpath should start with '/'");
+ }
+ // resUrl = "classpath:" + resUrl;
+ classpath = true;
+ } else {
+ classpath = false;
+ }
+
+ URL url;
+ Bundle dataModelBundle = null;
+ if (classpath) {
+ if (bundleContext != null) {
+ Bundle currentBundle = bundleContext.getBundle();
+ url = currentBundle.getResource(resUrl);
+ if (url != null) {// found
+ dataModelBundle = findDataModelBundle(resUrl);
+ }
+ } else {
+ url = getClass().getClassLoader().getResource(resUrl);
+ }
+ if (url == null)
+ throw new ArgeoException("No " + resUrl
+ + " in the classpath,"
+ + " make sure the containing"
+ + " package is visible.");
+
+ } else {
+ url = new URL(resUrl);
+ }
+
+ // check existing data model nodes
+ new NamespaceHelper(session).registerNamespace(
+ ArgeoNames.ARGEO, ArgeoNames.ARGEO_NAMESPACE);
+ if (!session
+ .itemExists(ArgeoJcrConstants.DATA_MODELS_BASE_PATH))
+ JcrUtils.mkdirs(session,
+ ArgeoJcrConstants.DATA_MODELS_BASE_PATH);
+ Node dataModels = session
+ .getNode(ArgeoJcrConstants.DATA_MODELS_BASE_PATH);
+ NodeIterator it = dataModels.getNodes();
+ Node dataModel = null;
+ while (it.hasNext()) {
+ Node node = it.nextNode();
+ if (node.getProperty(ArgeoNames.ARGEO_URI).getString()
+ .equals(resUrl)) {
+ dataModel = node;
+ break;
+ }
+ }
+
+ // does nothing if data model already registered
+ if (dataModel != null && !forceCndImport) {
+ if (dataModelBundle != null) {
+ String version = dataModel.getProperty(
+ ArgeoNames.ARGEO_DATA_MODEL_VERSION)
+ .getString();
+ String dataModelBundleVersion = dataModelBundle
+ .getVersion().toString();
+ if (!version.equals(dataModelBundleVersion)) {
+ log.warn("Data model with version "
+ + dataModelBundleVersion
+ + " available, current version is "
+ + version);
+ }
+ }
+ // do not implicitly update
+ return;
+ }