diff options
author | Paul Fullbright | 2012-08-20 16:30:03 +0000 |
---|---|---|
committer | Paul Fullbright | 2012-08-20 16:31:20 +0000 |
commit | 285778800a2ff1cbc0f1cf3e998a522bab622db2 (patch) | |
tree | 75ea581bd70f3631aba2d6cf2974a2f9d801a140 /common | |
parent | 05abb865678ead39da37fe70c9cb0fea2e89226b (diff) | |
download | webtools.dali-285778800a2ff1cbc0f1cf3e998a522bab622db2.tar.gz webtools.dali-285778800a2ff1cbc0f1cf3e998a522bab622db2.tar.xz webtools.dali-285778800a2ff1cbc0f1cf3e998a522bab622db2.zip |
Initial oxm resource model
Diffstat (limited to 'common')
15 files changed, 2452 insertions, 40 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF b/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF index f99ebc7944..c358a6c051 100644 --- a/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF +++ b/common/plugins/org.eclipse.jpt.common.core/META-INF/MANIFEST.MF @@ -17,49 +17,35 @@ Require-Bundle: org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)", org.eclipse.emf.ecore.xmi;bundle-version="[2.4.0,3.0.0)", org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)", org.eclipse.jdt.launching;bundle-version="[3.4.0,4.0.0)", + org.eclipse.jem.util;bundle-version="[2.1.100,3.0.0)", org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)", org.eclipse.jst.common.project.facet.core;bundle-version="[1.3.100,2.0.0)", org.eclipse.jst.j2ee;bundle-version="[1.1.200,2.0.0)", + org.eclipse.jst.j2ee.core;bundle-version="[1.2.200,2.0.0)", org.eclipse.pde.core;bundle-version="[3.6.0,4.0.0)";resolution:=optional, org.eclipse.text;bundle-version="[3.5.100,4.0.0)", org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)", + org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.2.101,2.0.0)", org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,2.0.0)", org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)", - org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)" + org.eclipse.wst.sse.core;bundle-version="[1.1.700,2.0.0)", + org.eclipse.wst.validation;bundle-version="[1.2.0,2.0.0)", + org.eclipse.wst.xml.core;bundle-version="[1.1.700,2.0.0)" Import-Package: com.ibm.icu.text;version="4.0.1" Dali-Comment: We friend 'internal.utility' to all non-EclipseLink, non-test bundles Export-Package: org.eclipse.jpt.common.core, org.eclipse.jpt.common.core.gen, - org.eclipse.jpt.common.core.internal; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.content; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.gen; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.libprov; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.libval; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.operations; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.resource; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.resource.java; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.resource.java.binary; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.resource.java.source; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.content;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.gen;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.libprov;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.libval;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.operations;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.resource;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.resource.java;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.resource.java.binary;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.resource.java.source;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.resource.xml;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", org.eclipse.jpt.common.core.internal.utility; x-friends:="org.eclipse.jpt.common.ui, org.eclipse.jpt.jaxb.core, @@ -69,19 +55,14 @@ Export-Package: org.eclipse.jpt.common.core, org.eclipse.jpt.jpa.db.ui, org.eclipse.jpt.jpa.gen, org.eclipse.jpt.jpa.ui", - org.eclipse.jpt.common.core.internal.utility.command; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.utility.jdt; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", - org.eclipse.jpt.common.core.internal.utility.translators; - x-friends:="org.eclipse.jpt.jaxb.core, - org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.utility.command;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.utility.jdt;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", + org.eclipse.jpt.common.core.internal.utility.translators;x-friends:="org.eclipse.jpt.jaxb.core,org.eclipse.jpt.jpa.core", org.eclipse.jpt.common.core.libprov, org.eclipse.jpt.common.core.libval, org.eclipse.jpt.common.core.resource, org.eclipse.jpt.common.core.resource.java, + org.eclipse.jpt.common.core.resource.xml, org.eclipse.jpt.common.core.utility, org.eclipse.jpt.common.core.utility.command, org.eclipse.jpt.common.core.utility.jdt diff --git a/common/plugins/org.eclipse.jpt.common.core/model/DaliEmfFormatter.xml b/common/plugins/org.eclipse.jpt.common.core/model/DaliEmfFormatter.xml new file mode 100644 index 0000000000..147065a21f --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/model/DaliEmfFormatter.xml @@ -0,0 +1,274 @@ +<?xml version="1.0" encoding="UTF-8"?>
<!-- + Copyright (c) 2007, 2010 Oracle. + All rights reserved. This program and the accompanying materials are + made available under the terms of the Eclipse Public License v1.0 which + accompanies this distribution, and is available at + http://www.eclipse.org/legal/epl-v10.html + + Contributors: + Oracle - initial API and implementation + --> + +<profiles version="11"> +<profile kind="CodeFormatterProfile" name="DaliEMFFormatter" version="11"> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="2"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="80"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="32"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="48"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="32"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/> +<setting id="org.eclipse.jdt.core.compiler.source" value="1.5"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="80"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="next_line"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.5"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="insert"/> +<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="true"/> +<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.5"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="52"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/> +<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="false"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/> +<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="true"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/> +<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/> +</profile> +</profiles> diff --git a/common/plugins/org.eclipse.jpt.common.core/model/common.ecore b/common/plugins/org.eclipse.jpt.common.core/model/common.ecore new file mode 100644 index 0000000000..5c57f5c1e1 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/model/common.ecore @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="xml" nsURI="jpt.common.xmi" nsPrefix="org.eclipse.jpt.jpa.core.resource.xml">
+ <eClassifiers xsi:type="ecore:EClass" name="ERootObjectImpl" abstract="true" eSuperTypes="#//ERootObject"/>
+ <eClassifiers xsi:type="ecore:EClass" name="ERootObject" abstract="true" interface="true">
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="version" lowerBound="1"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ <eStructuralFeatures xsi:type="ecore:EAttribute" name="schemaLocation" lowerBound="1"
+ eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
+ </eClassifiers>
+</ecore:EPackage>
diff --git a/common/plugins/org.eclipse.jpt.common.core/model/commonResourceModels.genmodel b/common/plugins/org.eclipse.jpt.common.core/model/commonResourceModels.genmodel new file mode 100644 index 0000000000..871c40227a --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/model/commonResourceModels.genmodel @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" modelDirectory="/org.eclipse.jpt.common.core/src" creationCommands="false"
+ creationIcons="false" editDirectory="" editorDirectory="" modelPluginID="org.eclipse.jpt.common.core"
+ modelName="Core" editPluginClass="" editorPluginClass="" updateClasspath="false"
+ rootExtendsInterface="org.eclipse.jpt.common.core.resource.xml.EBaseObject" rootExtendsClass="org.eclipse.jpt.common.core.resource.xml.EBaseObjectImpl"
+ suppressInterfaces="true" testsDirectory="" testSuiteClass="" importerID="org.eclipse.emf.importer.ecore"
+ complianceLevel="5.0" copyrightFields="false" editPluginID="org.eclipse.jpt.common.core.edit"
+ editorPluginID="org.eclipse.jpt.common.core.edit" testsPluginID="org.eclipse.jpt.common.core.edit">
+ <foreignModel>common.ecore</foreignModel>
+ <genPackages prefix="Common" basePackage="org.eclipse.jpt.common.core.resource"
+ disposableProviderFactory="true" adapterFactory="false" ecorePackage="common.ecore#/">
+ <genClasses image="false" ecoreClass="common.ecore#//ERootObjectImpl"/>
+ <genClasses image="false" ecoreClass="common.ecore#//ERootObject">
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute common.ecore#//ERootObject/version"/>
+ <genFeatures createChild="false" ecoreFeature="ecore:EAttribute common.ecore#//ERootObject/schemaLocation"/>
+ </genClasses>
+ </genPackages>
+</genmodel:GenModel>
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/xml/AbstractJptXmlResourceProvider.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/xml/AbstractJptXmlResourceProvider.java new file mode 100644 index 0000000000..ac9f709e79 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/xml/AbstractJptXmlResourceProvider.java @@ -0,0 +1,308 @@ +/******************************************************************************* + * Copyright (c) 2008, 2012 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.common.core.internal.resource.xml; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.URIConverter; +import org.eclipse.jem.util.emf.workbench.EMFWorkbenchContextBase; +import org.eclipse.jem.util.emf.workbench.FlexibleProjectResourceSet; +import org.eclipse.jem.util.emf.workbench.IEMFContextContributor; +import org.eclipse.jem.util.emf.workbench.ProjectResourceSet; +import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase; +import org.eclipse.jpt.common.core.internal.plugin.JptCommonCorePlugin; +import org.eclipse.jpt.common.core.resource.ProjectResourceLocator; +import org.eclipse.jpt.common.core.resource.xml.JpaXmlResourceProvider; +import org.eclipse.jpt.common.core.resource.xml.JptXmlResource; +import org.eclipse.wst.common.componentcore.internal.impl.WTPResourceFactoryRegistry; +import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper; +import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateInputProvider; +import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidator; +import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidatorImpl; +import org.eclipse.wst.common.internal.emfworkbench.validateedit.ResourceStateValidatorPresenter; + +/** + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 2.3 + * @since 2.2 + */ +public abstract class AbstractJptXmlResourceProvider + implements JpaXmlResourceProvider, IEMFContextContributor, ResourceStateInputProvider, ResourceStateValidator +{ + protected IProject project; + + protected URI fileUri; + + protected JptXmlResource resource; + + protected IContentType contentType; + + protected ResourceStateValidator stateValidator; + + + /** + * Create a new AbstractResourceModelProvider for the given project and + * resourcePath. The resourcePath may be either + * a) an absolute workspace-relative platform resource path (e.g. "/MyProject/src/META-INF/foobar.xml") + * or b) a relative runtime path (e.g. "META-INF/foobar.xml".) + * In either case, {@link #buildFileUri(IPath)} will attempt to build an absolutely pathed + * URI for the given path. + */ + public AbstractJptXmlResourceProvider(IProject project, IPath resourcePath, IContentType contentType) { + super(); + this.project = project; + this.fileUri = buildFileUri(resourcePath); + this.contentType = contentType; + } + + protected URI buildFileUri(IPath resourcePath) { + URI resourceUri = null; + + if (resourcePath.isAbsolute()) { + resourceUri = URI.createPlatformResourceURI(resourcePath.toString(), false); + } + else { + IPath absolutePath = this.getProjectResourceLocator().getResourcePath(resourcePath); + resourceUri = URI.createPlatformResourceURI(absolutePath.toString(), false); + } + + URIConverter uriConverter = getResourceSet().getURIConverter(); + return uriConverter.normalize(resourceUri); + } + + protected ProjectResourceLocator getProjectResourceLocator() { + return (ProjectResourceLocator) this.project.getAdapter(ProjectResourceLocator.class); + } + + /** + * Return the resource, if it exists. If no file exists for this resource, + * this will return a stub resource. You must call #createResource() to + * create the file on the file system. + */ + public JptXmlResource getXmlResource() { + if (this.resource == null) { + JptXmlResource newResource = (JptXmlResource) WorkbenchResourceHelper.getOrCreateResource(this.fileUri, getResourceSet()); + if (newResource == null) { + //ResourceSet "isReleasing", deleting the project causes this + return null; + } + //EMF caches resources based on URI. If the resource has changed content types (say the schema was changed + //from orm to eclipselink-orm), then the resource will be of the wrong type and we need to create a new one. + if (newResource.getContentType().equals(this.contentType)) { + this.resource = newResource; + } + else { + this.createResourceAndLoad(); + } + } + return this.resource; + } + + protected JptXmlResource createResourceAndLoad() { + this.resource = createResource(); + this.loadResource(); + return this.resource; + } + + protected JptXmlResource createResource() { + Resource.Factory resourceFactory = + WTPResourceFactoryRegistry.INSTANCE.getFactory(this.fileUri, this.contentType.getDefaultDescription()); + return (JptXmlResource) getResourceSet().createResource(this.fileUri, resourceFactory); + } + + protected void loadResource() { + try { + this.resource.load(((ProjectResourceSet) getResourceSet()).getLoadOptions()); + } + catch (IOException e) { + JptCommonCorePlugin.instance().logError(e); + } + } + + protected void createResourceAndUnderlyingFile(Object config) { + this.resource = createResource(); + if (this.resource.fileExists()) { //always possible that the file already exists when the jpa facet is added + loadResource(); + } + else { + populateRoot(config); + try { + this.resource.saveIfNecessary(); //this writes out the file + } + catch (Exception e) { + JptCommonCorePlugin.instance().logError(e); + } + } + } + + /** + * This will actually create the underlying file and the JptXmlResource that corresponds to it. + * It also populates the root of the file. + * @param config - A configuration object used to specify options for creation of the resource + */ + public JptXmlResource createFileAndResource(Object config, IProgressMonitor monitor) throws CoreException { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + IWorkspaceRunnable runnable = new CreateFileAndResourceWorkspaceRunnable(config); + workspace.run(runnable, this.project, IWorkspace.AVOID_UPDATE, monitor); + return this.resource; + } + + class CreateFileAndResourceWorkspaceRunnable + implements IWorkspaceRunnable + { + private final Object config; + CreateFileAndResourceWorkspaceRunnable(Object config) { + super(); + this.config = config; + } + public void run(IProgressMonitor monitor) { + AbstractJptXmlResourceProvider.this.createResourceAndUnderlyingFile(this.config); + } + } + + /** + * Used to optionally fill in the root information of a resource if it does not + * exist as a file + */ + protected void populateRoot(@SuppressWarnings("unused") Object config) { + //TODO potentially call resource.populateRoot() instead of the resourceProvider doing this + } + + + /** + * minimize the scope of the suppressed warnings + */ + protected EList<EObject> getResourceContents() { + return this.resource.getContents(); + } + + protected FlexibleProjectResourceSet getResourceSet() { + return (FlexibleProjectResourceSet) getEmfContext().getResourceSet(); + } + + protected EMFWorkbenchContextBase getEmfContext() { + return WorkbenchResourceHelperBase.createEMFContext(this.project, this); + } + + public IProject getProject() { + return this.project; + } + + public IStatus validateEdit(Object context) { + IWorkspace work = ResourcesPlugin.getWorkspace(); + IFile file = WorkbenchResourceHelper.getFile(this.resource); + if (file != null) { + IFile[] files = { file }; + if (context == null) { + context = IWorkspace.VALIDATE_PROMPT; + } + return work.validateEdit(files, context); + } + return Status.OK_STATUS; + } + + + // **************** IEMFContextContributor impl *************************** + + private boolean contributedToEmfContext = false; + + public void primaryContributeToContext(EMFWorkbenchContextBase context) { + if (! this.contributedToEmfContext) { + context.getResourceSet().setResourceFactoryRegistry(WTPResourceFactoryRegistry.INSTANCE); + this.contributedToEmfContext = true; + } + } + + public void secondaryContributeToContext(EMFWorkbenchContextBase aNature) { + // no op + } + + + // **************** ResourceStateValidator impl **************************** + + public ResourceStateValidator getStateValidator() { + if (this.stateValidator == null) { + this.stateValidator = createStateValidator(); + } + return this.stateValidator; + } + + private ResourceStateValidator createStateValidator() { + return new ResourceStateValidatorImpl(this); + } + + public void checkActivation(ResourceStateValidatorPresenter presenter) throws CoreException { + getStateValidator().checkActivation(presenter); + } + + public void lostActivation(ResourceStateValidatorPresenter presenter) throws CoreException { + getStateValidator().lostActivation(presenter); + } + + public IStatus validateState(ResourceStateValidatorPresenter presenter) throws CoreException { + return (presenter == null) ? Status.OK_STATUS : getStateValidator().validateState(presenter); + } + + public boolean checkSave(ResourceStateValidatorPresenter presenter) throws CoreException { + return getStateValidator().checkSave(presenter); + } + + public boolean checkReadOnly() { + return getStateValidator().checkReadOnly(); + } + + + // **************** ResourceStateInputProvider impl ************************ + + public boolean isDirty() { + return this.resource.isModified(); + } + + @SuppressWarnings("rawtypes") + public List getNonResourceFiles() { + return Collections.emptyList(); + } + + @SuppressWarnings("rawtypes") + public List getNonResourceInconsistentFiles() { + return Collections.emptyList(); + } + + @SuppressWarnings("rawtypes") + public List getResources() { + return Collections.singletonList(getXmlResource()); + } + + @SuppressWarnings("rawtypes") + public void cacheNonResourceValidateState(List roNonResourceFiles) { + // do nothing + } +} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonFactory.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonFactory.java new file mode 100644 index 0000000000..254d60e239 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonFactory.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jpt.common.core.resource.xml; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.impl.EFactoryImpl; +import org.eclipse.emf.ecore.plugin.EcorePlugin; + +/** + * <!-- begin-user-doc --> + * The <b>Factory</b> for the model. + * It provides a create method for each non-abstract class of the model. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * <!-- end-user-doc --> + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage + * @generated + */ +public class CommonFactory extends EFactoryImpl +{ + /** + * The singleton instance of the factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final CommonFactory eINSTANCE = init(); + + /** + * Creates the default factory implementation. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static CommonFactory init() + { + try + { + CommonFactory theCommonFactory = (CommonFactory)EPackage.Registry.INSTANCE.getEFactory("jpt.common.xmi"); + if (theCommonFactory != null) + { + return theCommonFactory; + } + } + catch (Exception exception) + { + EcorePlugin.INSTANCE.log(exception); + } + return new CommonFactory(); + } + + /** + * Creates an instance of the factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public CommonFactory() + { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public EObject create(EClass eClass) + { + switch (eClass.getClassifierID()) + { + default: + throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); + } + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public CommonPackage getCommonPackage() + { + return (CommonPackage)getEPackage(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @deprecated + * @generated + */ + @Deprecated + public static CommonPackage getPackage() + { + return CommonPackage.eINSTANCE; + } + +} //CommonFactory diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonPackage.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonPackage.java new file mode 100644 index 0000000000..62860008af --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/CommonPackage.java @@ -0,0 +1,416 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jpt.common.core.resource.xml; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.impl.EPackageImpl; + +/** + * <!-- begin-user-doc --> + * The <b>Package</b> for the model. + * It contains accessors for the meta objects to represent + * <ul> + * <li>each class,</li> + * <li>each feature of each class,</li> + * <li>each enum,</li> + * <li>and each data type</li> + * </ul> + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * <!-- end-user-doc --> + * @see org.eclipse.jpt.common.core.resource.xml.CommonFactory + * @model kind="package" + * @generated + */ +public class CommonPackage extends EPackageImpl +{ + /** + * The package name. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final String eNAME = "xml"; + + /** + * The package namespace URI. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final String eNS_URI = "jpt.common.xmi"; + + /** + * The package namespace name. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final String eNS_PREFIX = "org.eclipse.jpt.jpa.core.resource.xml"; + + /** + * The singleton instance of the package. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final CommonPackage eINSTANCE = org.eclipse.jpt.common.core.resource.xml.CommonPackage.init(); + + /** + * The meta object id for the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject <em>ERoot Object</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jpt.common.core.resource.xml.ERootObject + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject() + * @generated + */ + public static final int EROOT_OBJECT = 1; + + /** + * The feature id for the '<em><b>Version</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int EROOT_OBJECT__VERSION = 0; + + /** + * The feature id for the '<em><b>Schema Location</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int EROOT_OBJECT__SCHEMA_LOCATION = 1; + + /** + * The number of structural features of the '<em>ERoot Object</em>' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int EROOT_OBJECT_FEATURE_COUNT = 2; + + /** + * The meta object id for the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl <em>ERoot Object Impl</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObjectImpl() + * @generated + */ + public static final int EROOT_OBJECT_IMPL = 0; + + /** + * The feature id for the '<em><b>Version</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int EROOT_OBJECT_IMPL__VERSION = EROOT_OBJECT__VERSION; + + /** + * The feature id for the '<em><b>Schema Location</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int EROOT_OBJECT_IMPL__SCHEMA_LOCATION = EROOT_OBJECT__SCHEMA_LOCATION; + + /** + * The number of structural features of the '<em>ERoot Object Impl</em>' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int EROOT_OBJECT_IMPL_FEATURE_COUNT = EROOT_OBJECT_FEATURE_COUNT + 0; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private EClass eRootObjectImplEClass = null; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private EClass eRootObjectEClass = null; + + /** + * Creates an instance of the model <b>Package</b>, registered with + * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package + * package URI value. + * <p>Note: the correct way to create the package is via the static + * factory method {@link #init init()}, which also performs + * initialization of the package, or returns the registered package, + * if one already exists. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.emf.ecore.EPackage.Registry + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#eNS_URI + * @see #init() + * @generated + */ + private CommonPackage() + { + super(eNS_URI, CommonFactory.eINSTANCE); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private static boolean isInited = false; + + /** + * Creates, registers, and initializes the <b>Package</b> for this model, and for any others upon which it depends. + * + * <p>This method is used to initialize {@link CommonPackage#eINSTANCE} when that field is accessed. + * Clients should not invoke it directly. Instead, they should simply access that field to obtain the package. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #eNS_URI + * @see #createPackageContents() + * @see #initializePackageContents() + * @generated + */ + public static CommonPackage init() + { + if (isInited) return (CommonPackage)EPackage.Registry.INSTANCE.getEPackage(CommonPackage.eNS_URI); + + // Obtain or create and register package + CommonPackage theCommonPackage = (CommonPackage)(EPackage.Registry.INSTANCE.get(eNS_URI) instanceof CommonPackage ? EPackage.Registry.INSTANCE.get(eNS_URI) : new CommonPackage()); + + isInited = true; + + // Create package meta-data objects + theCommonPackage.createPackageContents(); + + // Initialize created meta-data + theCommonPackage.initializePackageContents(); + + // Mark meta-data to indicate it can't be changed + theCommonPackage.freeze(); + + + // Update the registry and return the package + EPackage.Registry.INSTANCE.put(CommonPackage.eNS_URI, theCommonPackage); + return theCommonPackage; + } + + + /** + * Returns the meta object for class '{@link org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl <em>ERoot Object Impl</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for class '<em>ERoot Object Impl</em>'. + * @see org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl + * @generated + */ + public EClass getERootObjectImpl() + { + return eRootObjectImplEClass; + } + + + /** + * Returns the meta object for class '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject <em>ERoot Object</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for class '<em>ERoot Object</em>'. + * @see org.eclipse.jpt.common.core.resource.xml.ERootObject + * @generated + */ + public EClass getERootObject() + { + return eRootObjectEClass; + } + + + /** + * Returns the meta object for the attribute '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getVersion <em>Version</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Version</em>'. + * @see org.eclipse.jpt.common.core.resource.xml.ERootObject#getVersion() + * @see #getERootObject() + * @generated + */ + public EAttribute getERootObject_Version() + { + return (EAttribute)eRootObjectEClass.getEStructuralFeatures().get(0); + } + + + /** + * Returns the meta object for the attribute '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getSchemaLocation <em>Schema Location</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Schema Location</em>'. + * @see org.eclipse.jpt.common.core.resource.xml.ERootObject#getSchemaLocation() + * @see #getERootObject() + * @generated + */ + public EAttribute getERootObject_SchemaLocation() + { + return (EAttribute)eRootObjectEClass.getEStructuralFeatures().get(1); + } + + + /** + * Returns the factory that creates the instances of the model. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the factory that creates the instances of the model. + * @generated + */ + public CommonFactory getCommonFactory() + { + return (CommonFactory)getEFactoryInstance(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private boolean isCreated = false; + + /** + * Creates the meta-model objects for the package. This method is + * guarded to have no affect on any invocation but its first. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void createPackageContents() + { + if (isCreated) return; + isCreated = true; + + // Create classes and their features + eRootObjectImplEClass = createEClass(EROOT_OBJECT_IMPL); + + eRootObjectEClass = createEClass(EROOT_OBJECT); + createEAttribute(eRootObjectEClass, EROOT_OBJECT__VERSION); + createEAttribute(eRootObjectEClass, EROOT_OBJECT__SCHEMA_LOCATION); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private boolean isInitialized = false; + + /** + * Complete the initialization of the package and its meta-model. This + * method is guarded to have no affect on any invocation but its first. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void initializePackageContents() + { + if (isInitialized) return; + isInitialized = true; + + // Initialize package + setName(eNAME); + setNsPrefix(eNS_PREFIX); + setNsURI(eNS_URI); + + // Create type parameters + + // Set bounds for type parameters + + // Add supertypes to classes + eRootObjectImplEClass.getESuperTypes().add(this.getERootObject()); + + // Initialize classes and features; add operations and parameters + initEClass(eRootObjectImplEClass, ERootObjectImpl.class, "ERootObjectImpl", IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + + initEClass(eRootObjectEClass, ERootObject.class, "ERootObject", IS_ABSTRACT, IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEAttribute(getERootObject_Version(), ecorePackage.getEString(), "version", null, 1, 1, ERootObject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getERootObject_SchemaLocation(), ecorePackage.getEString(), "schemaLocation", null, 1, 1, ERootObject.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + // Create resource + createResource(eNS_URI); + } + + /** + * <!-- begin-user-doc --> + * Defines literals for the meta objects that represent + * <ul> + * <li>each class,</li> + * <li>each feature of each class,</li> + * <li>each enum,</li> + * <li>and each data type</li> + * </ul> + * <!-- end-user-doc --> + * @generated + */ + public interface Literals + { + /** + * The meta object literal for the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl <em>ERoot Object Impl</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObjectImpl() + * @generated + */ + public static final EClass EROOT_OBJECT_IMPL = eINSTANCE.getERootObjectImpl(); + + /** + * The meta object literal for the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject <em>ERoot Object</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jpt.common.core.resource.xml.ERootObject + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject() + * @generated + */ + public static final EClass EROOT_OBJECT = eINSTANCE.getERootObject(); + + /** + * The meta object literal for the '<em><b>Version</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute EROOT_OBJECT__VERSION = eINSTANCE.getERootObject_Version(); + + /** + * The meta object literal for the '<em><b>Schema Location</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute EROOT_OBJECT__SCHEMA_LOCATION = eINSTANCE.getERootObject_SchemaLocation(); + + } + +} //CommonPackage diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EBaseObject.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EBaseObject.java new file mode 100644 index 0000000000..43b65f916d --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EBaseObject.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ + +package org.eclipse.jpt.common.core.resource.xml; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.text.edits.DeleteEdit; + +/** + * Common Dali behavior for EMF objects. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 2.2 + */ +public interface EBaseObject + extends EObject +{ + /** + * Return whether all the object's EMF features are "unset". + */ + boolean isUnset(); + + /** + * Return true if this object's text representation contains the text offset + */ + boolean containsOffset(int textOffset); + + /** + * Return the text range to be used for validation. This is the source + * range that will be highlighted for a validation error. + */ + TextRange getValidationTextRange(); + + /** + * Return the text range to be used for selection. This is the source + * range that will be highlighted when selecting in the structure view. + */ + TextRange getSelectionTextRange(); + + + // ********** refactoring ********** + + /** + * Create a text DeleteEdit for deleting the entire IDOMNode and any text that precedes it. + */ + DeleteEdit createDeleteEdit(); +} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EBaseObjectImpl.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EBaseObjectImpl.java new file mode 100644 index 0000000000..dde1fe11dc --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EBaseObjectImpl.java @@ -0,0 +1,366 @@ +/******************************************************************************* + * Copyright (c) 2006, 2012 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.core.resource.xml; + +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Set; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.impl.EObjectImpl; +import org.eclipse.jpt.common.core.internal.utility.SimpleTextRange; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.text.edits.DeleteEdit; +import org.eclipse.wst.common.internal.emf.resource.EMF2DOMAdapter; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 3.0 + * @since 2.2 + */ +public abstract class EBaseObjectImpl + extends EObjectImpl + implements EBaseObject +{ + protected IDOMNode node; + + /** + * Sets of "insignificant" feature ids, keyed by class. + * This is built up lazily, as the objects are modified. + */ + private static final Hashtable<Class<? extends EBaseObjectImpl>, HashSet<Integer>> insignificantFeatureIdSets = new Hashtable<Class<? extends EBaseObjectImpl>, HashSet<Integer>>(); + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected EBaseObjectImpl() { + super(); + } + + + // ********** EBaseObject implementation ********** + + public boolean isUnset() { + for (EStructuralFeature feature : this.eClass().getEAllStructuralFeatures()) { + if (this.eIsSet(feature)) { + return false; + } + } + return true; + } + + + // ********** change notification ********** + + /** + * override to build a custom list for the adapters + */ + @Override + public EList<Adapter> eAdapters() { + if (this.eAdapters == null) { + this.eAdapters = new XmlEAdapterList<Adapter>(this); + } + return this.eAdapters; + } + + /** + * override to prevent notification when the object's state is unchanged + */ + @Override + public void eNotify(Notification notification) { + if ( ! notification.isTouch()) { + super.eNotify(notification); + this.featureChanged(notification.getFeatureID(this.getClass())); + } + } + + protected void featureChanged(int featureId) { + if (this.featureIsSignificant(featureId)) { + this.getXmlResource().resourceModelChanged(); + } + } + + protected JptXmlResource getXmlResource() { + return (JptXmlResource) this.eResource(); + } + + protected boolean featureIsSignificant(int featureId) { + return ! this.featureIsInsignificant(featureId); + } + + protected boolean featureIsInsignificant(int featureId) { + return this.insignificantFeatureIds().contains(Integer.valueOf(featureId)); + } + + /** + * Return a set of the object's "insignificant" feature ids. + * These are the EMF features that will not be used to determine if all + * the features are unset. We use this to determine when to remove + * an element from the xml. + * + * If you need instance-based calculation of your xml "insignificant" aspects, + * override this method. If class-based calculation is sufficient, + * override #addInsignificantXmlFeatureIdsTo(Set). + * + * @see #isUnset() + */ + protected Set<Integer> insignificantFeatureIds() { + synchronized (insignificantFeatureIdSets) { + HashSet<Integer> insignificantXmlFeatureIds = insignificantFeatureIdSets.get(this.getClass()); + if (insignificantXmlFeatureIds == null) { + insignificantXmlFeatureIds = new HashSet<Integer>(); + this.addInsignificantXmlFeatureIdsTo(insignificantXmlFeatureIds); + insignificantFeatureIdSets.put(this.getClass(), insignificantXmlFeatureIds); + } + return insignificantXmlFeatureIds; + } + } + + /** + * Add the object's "insignificant" feature ids to the specified set. + * These are the EMF features that, when they change, will NOT cause the + * object (or its containing tree) to be updated, i.e. defaults calculated. + * If class-based calculation of your "insignificant" features is sufficient, + * override this method. If you need instance-based calculation, + * override #insignificantXmlFeatureIds(). + */ + protected void addInsignificantXmlFeatureIdsTo(@SuppressWarnings("unused") Set<Integer> insignificantXmlFeatureIds) { + // when you override this method, don't forget to include: + // super.addInsignificantXmlFeatureIdsTo(insignificantXmlFeatureIds); + } + + + // ********** text ranges ********** + + /** + * Return a text range for the "text" node. + * If the text node does not exist, return a text range for this object's node + */ + protected TextRange getTextTextRange() { + IDOMNode textNode = this.getTextNode(); + return (textNode != null) ? this.buildTextRange(textNode) : this.getValidationTextRange(); + } + + protected IDOMNode getTextNode() { + // TODO bjv null check no longer needed? (orm nodes are no longer virtual) + // virtual objects have no node + return (this.node == null) ? null : selectTextNode(this.node.getChildNodes()); + } + + + protected IDOMNode selectTextNode(NodeList nodes) { + for (int i = 0; i < nodes.getLength(); i++) { + IDOMNode n = (IDOMNode) nodes.item(i); + if (n.getNodeType() == Node.TEXT_NODE) { + return n; + } + } + return null; + } + + /** + * Return a text range for the specified attribute node. + * If the attribute node does not exist, return a text range for this object's + * node + */ + protected TextRange getAttributeTextRange(String attributeName) { + IDOMNode attributeNode = this.getAttributeNode(attributeName); + return (attributeNode != null) ? this.buildTextRange(attributeNode) : this.getValidationTextRange(); + } + + protected IDOMAttr getAttributeNode(String attributeName) { + return (this.node == null) ? // virtual objects have no node + null : (IDOMAttr) this.node.getAttributes().getNamedItem(attributeName); + } + + /** + * Return a text range for the specified element node. + * If the element node does not exist, return a text range for this object's + * node + */ + protected TextRange getElementTextRange(String elementName) { + IDOMNode elementNode = this.getElementNode(elementName); + return (elementNode != null) ? this.buildTextRange(elementNode) : this.getValidationTextRange(); + } + + /** + * Returns the first element node with the given name, if one exists + */ + protected IDOMNode getElementNode(String elementName) { + if (this.node == null) return null; // virtual objects have no node + NodeList children = this.node.getChildNodes(); + for (int i = 0; i < children.getLength(); i ++) { + IDOMNode child = (IDOMNode) children.item(i); + if ((child.getNodeType() == Node.ELEMENT_NODE) + && elementName.equals(child.getNodeName())) { + return child; + } + } + return null; + } + + public TextRange getValidationTextRange() { + return this.getFullTextRange(); + } + + public TextRange getSelectionTextRange() { + return this.getFullTextRange(); + } + + protected TextRange getFullTextRange() { + return this.buildTextRange(this.node); + } + + protected TextRange buildTextRange(IDOMNode domNode) { + return (domNode == null) ? null : this.buildTextRange_(domNode, null); + } + + protected TextRange buildTextRange(IDOMNode domNode, TextRange textRange) { + return (domNode == null) ? null : this.buildTextRange_(domNode, textRange); + } + + /** + * pre-condition: the specified DOM node is not <code>null</code> + */ + protected TextRange buildTextRange_(IDOMNode domNode, TextRange textRange) { + int offset = domNode.getStartOffset(); + int length = (domNode.getNodeType() == Node.ELEMENT_NODE) ? + (((IDOMElement) domNode).getStartEndOffset() - offset) : + domNode.getLength(); + int lineNumber = domNode.getStructuredDocument().getLineOfOffset(offset) + 1; + return (textRange == null) ? + new SimpleTextRange(offset, length, lineNumber) : + textRange.buildTextRange(offset, length, lineNumber); + } + + public boolean containsOffset(int textOffset) { + return (this.node == null) ? false : this.node.contains(textOffset); + } + + + // ********** content assist ********** + + /** + * Return a text range for the specified attribute node. + * If the attribute node does not exist, return null + * + * This is used for content assist to return the exact text range of an attribute. + * It is different from the text range used by validation which returns + * the parent's text range if the specified attribute node does not exist + */ + protected TextRange getAttributeCodeAssistTextRange(String attributeName) { + IDOMNode attributeNode = this.getAttributeNode(attributeName); + return (attributeNode != null) ? this.buildTextRange(attributeNode) : null; + } + + /** + * Return a text range for the specified element node. + * If the element node does not exist, return null + * + * This is used for content assist to return the exact text range of an element. + * It is different from the text range used by validation which returns + * the parent's text range if the specified element node does not exist + */ + protected TextRange getElementCodeAssistTextRange(String elementName) { + IDOMNode elementNode = this.getElementNode(elementName); + return (elementNode != null) ? this.buildElementCodeAssistTextRange(elementNode) : null; + } + + protected TextRange buildElementCodeAssistTextRange(IDOMNode domNode) { + return (domNode == null) ? null : this.buildElementCodeAssistTextRange(domNode, null); + } + + protected TextRange buildElementCodeAssistTextRange(IDOMNode domNode, TextRange textRange) { + return (domNode == null) ? null : this.buildElementCodeAssistTextRange_(domNode, textRange); + } + /** + * pre-condition: the specified DOM node is not <code>null</code> + */ + protected TextRange buildElementCodeAssistTextRange_(IDOMNode domNode, TextRange textRange) { + int offset = domNode.getStartOffset(); + int length = (domNode.getNodeType() == Node.ELEMENT_NODE) ? + (((IDOMElement) domNode).getEndStartOffset() - offset) : + domNode.getLength(); + int lineNumber = domNode.getStructuredDocument().getLineOfOffset(offset) + 1; + return (textRange == null) ? + new SimpleTextRange(offset, length, lineNumber) : + textRange.buildTextRange(offset, length, lineNumber); + } + + // ********** Refactoring TextEdits ********** + + public DeleteEdit createDeleteEdit() { + int deletionOffset = getDeletionOffset(); + int deletionLength = this.node.getEndOffset() - deletionOffset; + return new DeleteEdit(deletionOffset, deletionLength); + } + + public int getNodeEndOffset() { + return this.node.getEndOffset(); + } + + /** + * deletion offset needs to include any text that is before the node + */ + protected int getDeletionOffset() { + int emptyTextLength = 0; + Node previousSibling = this.node.getPreviousSibling(); + if (previousSibling != null && previousSibling.getNodeType() == Node.TEXT_NODE) { + emptyTextLength = ((Text) previousSibling).getLength(); + } + return this.node.getStartOffset() - emptyTextLength; + } + + + // ********** custom adapter list ********** + + protected static class XmlEAdapterList<E extends Object & Adapter> + extends EAdapterList<E> + { + public XmlEAdapterList(EBaseObjectImpl jpaEObject) { + super(jpaEObject); + } + + @Override + protected void didAdd(int index, E newObject) { + super.didAdd(index, newObject); + if (newObject instanceof EMF2DOMAdapter) { + Object n = ((EMF2DOMAdapter) newObject).getNode(); + if (n instanceof IDOMNode) { + ((EBaseObjectImpl) this.notifier).node = (IDOMNode) n; + } + } + } + + @Override + protected void didRemove(int index, E oldObject) { + if ((oldObject instanceof EMF2DOMAdapter) && + (((EMF2DOMAdapter) oldObject).getNode() == ((EBaseObjectImpl) this.notifier).node)) { + ((EBaseObjectImpl) this.notifier).node = null; + } + super.didRemove(index, oldObject); + } + } +} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObject.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObject.java new file mode 100644 index 0000000000..8f9fec5fbc --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObject.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jpt.common.core.resource.xml; + +import org.eclipse.jpt.common.core.utility.TextRange; + + +/** + * <!-- begin-user-doc --> + * A representation of the model object '<em><b>Jpa Root EObject</b></em>'. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * <!-- end-user-doc --> + * + * <p> + * The following features are supported: + * <ul> + * <li>{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getVersion <em>Version</em>}</li> + * <li>{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getSchemaLocation <em>Schema Location</em>}</li> + * </ul> + * </p> + * + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject() + * @model kind="class" interface="true" abstract="true" + * @extends EBaseObject + * @generated + */ +public interface ERootObject extends EBaseObject +{ + /** + * Returns the value of the '<em><b>Version</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Version</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Version</em>' attribute. + * @see #setVersion(String) + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject_Version() + * @model required="true" + * @generated + */ + String getVersion(); + + /** + * Sets the value of the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getVersion <em>Version</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Version</em>' attribute. + * @see #getVersion() + * @generated + */ + void setVersion(String value); + + /** + * Returns the value of the '<em><b>Schema Location</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Schema Location</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Schema Location</em>' attribute. + * @see #setSchemaLocation(String) + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject_SchemaLocation() + * @model required="true" + * @generated + */ + String getSchemaLocation(); + + /** + * Sets the value of the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObject#getSchemaLocation <em>Schema Location</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Schema Location</em>' attribute. + * @see #getSchemaLocation() + * @generated + */ + void setSchemaLocation(String value); + + TextRange getVersionTextRange(); +} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObjectImpl.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObjectImpl.java new file mode 100644 index 0000000000..c11f483a0a --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/ERootObjectImpl.java @@ -0,0 +1,335 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Oracle. + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jpt.common.core.resource.xml; + +import java.util.Map; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.impl.ENotificationImpl; +import org.eclipse.jpt.common.core.internal.utility.translators.EnumeratedValueTranslator; +import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; +import org.eclipse.wst.common.internal.emf.resource.ConstantAttributeTranslator; +import org.eclipse.wst.common.internal.emf.resource.Translator; + +/** + * <!-- begin-user-doc --> + * A representation of the model object '<em><b>Abstract Jpa Root EObject</b></em>'. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * <!-- end-user-doc --> + * + * + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObjectImpl() + * @model kind="class" abstract="true" + * @generated + */ +public abstract class ERootObjectImpl extends EBaseObjectImpl implements ERootObject +{ + /** + * The default value of the '{@link #getVersion() <em>Version</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getVersion() + * @generated + * @ordered + */ + protected static final String VERSION_EDEFAULT = null; + + /** + * The cached value of the '{@link #getVersion() <em>Version</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getVersion() + * @generated + * @ordered + */ + protected String version = VERSION_EDEFAULT; + + /** + * The default value of the '{@link #getSchemaLocation() <em>Schema Location</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSchemaLocation() + * @generated + * @ordered + */ + protected static final String SCHEMA_LOCATION_EDEFAULT = null; + + /** + * The cached value of the '{@link #getSchemaLocation() <em>Schema Location</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSchemaLocation() + * @generated + * @ordered + */ + protected String schemaLocation = SCHEMA_LOCATION_EDEFAULT; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected ERootObjectImpl() + { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + protected EClass eStaticClass() + { + return CommonPackage.Literals.EROOT_OBJECT_IMPL; + } + + /** + * Returns the value of the '<em><b>Version</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Version</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Version</em>' attribute. + * @see #setVersion(String) + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject_Version() + * @model required="true" + * @generated + */ + public String getVersion() + { + return version; + } + + /** + * Sets the value of the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl#getVersion <em>Version</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Version</em>' attribute. + * @see #getVersion() + * @generated + */ + protected void setVersionGen(String newVersion) + { + String oldVersion = version; + version = newVersion; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, CommonPackage.EROOT_OBJECT_IMPL__VERSION, oldVersion, version)); + } + + public void setVersion(String newVersion) { + setVersionGen(newVersion); + setSchemaLocation(buildSchemaLocationString(getNamespace(), getSchemaLocationForVersion(newVersion))); + } + + /** + * Returns the value of the '<em><b>Schema Location</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Schema Location</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Schema Location</em>' attribute. + * @see #setSchemaLocation(String) + * @see org.eclipse.jpt.common.core.resource.xml.CommonPackage#getERootObject_SchemaLocation() + * @model required="true" + * @generated + */ + public String getSchemaLocation() + { + return schemaLocation; + } + + /** + * Sets the value of the '{@link org.eclipse.jpt.common.core.resource.xml.ERootObjectImpl#getSchemaLocation <em>Schema Location</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Schema Location</em>' attribute. + * @see #getSchemaLocation() + * @generated + */ + public void setSchemaLocation(String newSchemaLocation) + { + String oldSchemaLocation = schemaLocation; + schemaLocation = newSchemaLocation; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION, oldSchemaLocation, schemaLocation)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public Object eGet(int featureID, boolean resolve, boolean coreType) + { + switch (featureID) + { + case CommonPackage.EROOT_OBJECT_IMPL__VERSION: + return getVersion(); + case CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION: + return getSchemaLocation(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void eSet(int featureID, Object newValue) + { + switch (featureID) + { + case CommonPackage.EROOT_OBJECT_IMPL__VERSION: + setVersion((String)newValue); + return; + case CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION: + setSchemaLocation((String)newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public void eUnset(int featureID) + { + switch (featureID) + { + case CommonPackage.EROOT_OBJECT_IMPL__VERSION: + setVersion(VERSION_EDEFAULT); + return; + case CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION: + setSchemaLocation(SCHEMA_LOCATION_EDEFAULT); + return; + } + super.eUnset(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public boolean eIsSet(int featureID) + { + switch (featureID) + { + case CommonPackage.EROOT_OBJECT_IMPL__VERSION: + return VERSION_EDEFAULT == null ? version != null : !VERSION_EDEFAULT.equals(version); + case CommonPackage.EROOT_OBJECT_IMPL__SCHEMA_LOCATION: + return SCHEMA_LOCATION_EDEFAULT == null ? schemaLocation != null : !SCHEMA_LOCATION_EDEFAULT.equals(schemaLocation); + } + return super.eIsSet(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + @Override + public String toString() + { + if (eIsProxy()) return super.toString(); + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (version: "); + result.append(version); + result.append(", schemaLocation: "); + result.append(schemaLocation); + result.append(')'); + return result.toString(); + } + + + // **************** validation ******************************************** + + public TextRange getVersionTextRange() { + return getAttributeTextRange(XML.VERSION); + } + + + // **************** version -> schema location mapping ******************** + + protected abstract String getNamespace(); + + protected abstract String getSchemaLocationForVersion(String version); + + private static String buildSchemaLocationString(String namespace, String schemaLocation) { + return namespace + ' ' + schemaLocation; + } + + + // **************** translators ******************************************* + + protected static Translator buildVersionTranslator(final Map<String, String> versionsToSchemaLocations) { + return new EnumeratedValueTranslator( + XML.VERSION, + CommonPackage.eINSTANCE.getERootObject_Version(), + Translator.DOM_ATTRIBUTE) { + + @Override + protected Iterable<String> getEnumeratedObjectValues() { + return versionsToSchemaLocations.keySet(); + } + }; + } + + protected static Translator buildNamespaceTranslator(String namespace) { + return new ConstantAttributeTranslator(XML.NAMESPACE, namespace); + } + + protected static Translator buildSchemaNamespaceTranslator() { + return new ConstantAttributeTranslator(XML.NAMESPACE_XSI, XML.XSI_NAMESPACE_URL); + } + + protected static Translator buildSchemaLocationTranslator( + final String namespace, + final Map<String, String> versionsToSchemaLocations) { + + return new EnumeratedValueTranslator( + XML.XSI_SCHEMA_LOCATION, + CommonPackage.eINSTANCE.getERootObject_SchemaLocation(), + Translator.DOM_ATTRIBUTE) { + + @Override + protected Iterable<String> getEnumeratedObjectValues() { + return new TransformationIterable<String, String>(versionsToSchemaLocations.values()) { + @Override + protected String transform(String next) { + return buildSchemaLocationString(namespace, next); + } + }; + } + }; + } +} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EmfTools.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EmfTools.java new file mode 100644 index 0000000000..e3d21218aa --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/EmfTools.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.core.resource.xml; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EFactory; +import org.eclipse.emf.ecore.EObject; + +/** + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 2.3 + * @since 2.3 + */ +public class EmfTools { + + public static <T extends EObject> T create(EFactory eFactory, EClass eClass, Class<T> javaClass) { + for (EClassifier factoryEClassifier : eFactory.getEPackage().getEClassifiers()) { + if (factoryEClassifier instanceof EClass) { + EClass factoryEClass = (EClass) factoryEClassifier; + if (eClass.isSuperTypeOf(factoryEClass)) { + return javaClass.cast(eFactory.create(factoryEClass)); + } + } + } + throw new IllegalArgumentException("Factory does not support objects of type \'" + eClass.getName() + '\''); //$NON-NLS-1$ + } +} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JpaXmlResourceProvider.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JpaXmlResourceProvider.java new file mode 100644 index 0000000000..e303afde26 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JpaXmlResourceProvider.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2008, 2012 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.common.core.resource.xml; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; + +/** + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 2.2 + * @since 2.2 + */ +public interface JpaXmlResourceProvider { + + JptXmlResource getXmlResource(); + + IStatus validateEdit(Object context); + + JptXmlResource createFileAndResource(Object config, IProgressMonitor monitor) throws CoreException; +} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java new file mode 100644 index 0000000000..7ee51dc154 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java @@ -0,0 +1,322 @@ +/******************************************************************************* + * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.core.resource.xml; + +import java.io.IOException; +import java.util.Collections; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase; +import org.eclipse.jem.util.plugin.JEMUtilPlugin; +import org.eclipse.jpt.common.core.ContentTypeReference; +import org.eclipse.jpt.common.core.JptResourceModel; +import org.eclipse.jpt.common.core.JptResourceModelListener; +import org.eclipse.jpt.common.core.JptResourceType; +import org.eclipse.jpt.common.core.internal.plugin.JptCommonCorePlugin; +import org.eclipse.jpt.common.core.internal.utility.PlatformTools; +import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.jst.j2ee.internal.xml.J2EEXmlDtDEntityResolver; +import org.eclipse.wst.common.internal.emf.resource.Renderer; +import org.eclipse.wst.common.internal.emf.resource.Translator; +import org.eclipse.wst.common.internal.emf.resource.TranslatorResourceImpl; +import org.xml.sax.EntityResolver; + +/** + * To retrieve the JPA XML resource corresponding to an Eclipse file: + * <pre> + * IFile file = (IFile) ResourcesPlugin.getWorkspace().getRoot().findMember("Foo.java"); + * JptXmlResource jpaXmlResource = (JptXmlResource) file.getAdapter(JptXmlResource.class); + * </pre> + * This is a non-blocking call; and as a result it will return <code>null</code> + * if the JPA XML resource or its JPA project is currently under construction. + * <p> + * See <code>org.eclipse.jpt.jpa.core/plugin.xml:org.eclipse.core.runtime.adapters</code>. + * <p> + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 2.3 + * @since 2.2 + */ +public class JptXmlResource + extends TranslatorResourceImpl + implements JptResourceModel, ContentTypeReference +{ + /** + * cache the content type - if the content type changes, the JPA project + * will throw out the JPA file holding the xml resource and build a new one + */ + protected final IContentType contentType; + + protected final Translator rootTranslator; + + protected final ListenerList<JptResourceModelListener> resourceModelListenerList = + new ListenerList<JptResourceModelListener>(JptResourceModelListener.class); + + + public JptXmlResource(URI uri, Renderer renderer, IContentType contentType, Translator rootTranslator) { + super(uri, renderer); + this.contentType = contentType; + this.rootTranslator = rootTranslator; + } + + public IContentType getContentType() { + return this.contentType; + } + + public String getVersion() { + ERootObject root = this.getRootObject(); + return (root == null) ? null : root.getVersion(); + } + + /** + * The XML schema version is required. + */ + public JptResourceType getResourceType() { + String version = this.getVersion(); + return (version == null) ? null : this.getResourceType(version); + } + + protected JptResourceType getResourceType(String version) { + return (this.contentType == null) ? null : PlatformTools.getResourceType(this.contentType, version); + } + + + // ********** BasicNotifierImpl override ********** + + /** + * Override to fire notification only when:<ul> + * <li>the resource's state has actually changed; and + * <li>the resource is loaded; and + * <li>the resource's resource set is still present (EMF will fire an + * notification when the resource set is set to 'null', just before + * the resource is "unloaded" - we want to swallow this notification) + * </ul> + */ + @Override + public void eNotify(Notification notification) { + // unload events can happen before the resource set is removed - should always react to unload events + if (this.loadedFlagCleared(notification)) { + super.eNotify(notification); + if (this.isReverting()) {// closing a modified file without saving + this.resourceModelReverted(); + } else { + this.resourceModelUnloaded(); + } + } + else if ( ! notification.isTouch() && this.isLoaded() && (this.resourceSet != null)) { + super.eNotify(notification); + this.resourceModelChanged(); + } + } + + /** + * Return whether the specified notification indicates the resource has been + * unloaded. + * we could use this method to suppress some notifications; or we could just + * check whether 'resourceSet' is 'null' (which is what we do) + */ + protected boolean loadedFlagCleared(Notification notification) { + return (notification.getNotifier() == this) && + (notification.getEventType() == Notification.SET) && + (notification.getFeatureID(Resource.class) == RESOURCE__IS_LOADED) && + ( ! notification.getNewBooleanValue()); + } + + /** + * Return whether the specified notification indicates the resource's + * resource set was cleared. + * We could use this method to suppress some resource set notifications; + * or we could just check whether <code>resourceSet</code> is + * <code>null</code> (which is what we do)/ + */ + protected boolean resultSetCleared(Notification notification) { + return (notification.getNotifier() == this) && + (notification.getEventType() == Notification.SET) && + (notification.getFeatureID(Resource.class) == RESOURCE__RESOURCE_SET) && + (notification.getNewValue() == null); + } + + + // ********** TranslatorResource implementation ********** + + /** + * only applicable for DTD-based files + */ + public String getDoctype() { + return null; + } + + public Translator getRootTranslator() { + return this.rootTranslator; + } + + + // ********** TranslatorResourceImpl implementation ********** + + /** + * only applicable for DTD-based files + */ + @Override + protected String getDefaultPublicId() { + return null; + } + + /** + * only applicable for DTD-based files + */ + @Override + protected String getDefaultSystemId() { + return null; + } + + /** + * this seems to be the default version of the spec for this doc + * and the id 10 maps to the version 1.0 + */ + @Override + protected int getDefaultVersionID() { + return 10; + } + + @Override + public ERootObject getRootObject() { + EObject root = super.getRootObject(); + try { + return (ERootObject) root; + } catch (ClassCastException ex) { + throw new IllegalStateException("The root object of a JPA XML resource must implement ERootObject: " + root, ex); //$NON-NLS-1$ + } + } + + //296544 - override this to avoid internet access finding the schema during tests + @Override + public EntityResolver getEntityResolver() { + return J2EEXmlDtDEntityResolver.INSTANCE; + } + + + // ********** convenience methods ********** + + public boolean fileExists() { + return this.getFile().exists(); + } + + public IFile getFile() { + IFile file = this.getFile(this.uri); + return (file != null) ? file : this.getConvertedURIFile(); + } + + protected IFile getConvertedURIFile() { + if (this.resourceSet == null) { + return null; + } + URI convertedURI = this.resourceSet.getURIConverter().normalize(this.uri); + return this.uri.equals(convertedURI) ? null : this.getFile(convertedURI); + } + + /** + * Return the Eclipse file for the specified URI. + * This URI is assumed to be absolute in the following format: + * platform:/resource/.... + */ + protected IFile getFile(URI fileURI) { + if ( ! WorkbenchResourceHelperBase.isPlatformResourceURI(fileURI)) { + return null; + } + String fileName = URI.decode(fileURI.path()).substring(JEMUtilPlugin.PLATFORM_RESOURCE.length() + 1); + return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileName)); + } + + public void save() { + try { + this.save(Collections.EMPTY_MAP); + } catch (IOException ex) { + JptCommonCorePlugin.instance().logError(ex); + } + } + + @Override + public String toString() { + // implementation in TranslatorResourceImpl is a bit off... + return StringTools.buildToStringFor(this, this.getURI()); + } + + + // ********** JptResourceModel implementation ********** + + public void addResourceModelListener(JptResourceModelListener listener) { + this.resourceModelListenerList.add(listener); + } + + public void removeResourceModelListener(JptResourceModelListener listener) { + this.resourceModelListenerList.remove(listener); + } + + + // ********** listener notifications ********** + + protected void resourceModelChanged() { + for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) { + try { + listener.resourceModelChanged(this); + } catch (Exception ex) { + JptCommonCorePlugin.instance().logError(ex); + } + } + } + + protected void resourceModelReverted() { + for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) { + try { + listener.resourceModelReverted(this); + } catch (Exception ex) { + JptCommonCorePlugin.instance().logError(ex); + } + } + } + + protected void resourceModelUnloaded() { + for (JptResourceModelListener listener : this.resourceModelListenerList.getListeners()) { + try { + listener.resourceModelUnloaded(this); + } catch (Exception ex) { + JptCommonCorePlugin.instance().logError(ex); + } + } + } + + + // ********** cast things back to what they are in EMF ********** + + @SuppressWarnings("unchecked") + @Override + public EList<Adapter> eAdapters() { + return super.eAdapters(); + } + + @SuppressWarnings("unchecked") + @Override + public EList<EObject> getContents() { + return super.getContents(); + } +} diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/XML.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/XML.java new file mode 100644 index 0000000000..575a2f8750 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/XML.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.common.core.resource.xml; + +/** + * XML-related stuff. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + * + * @version 2.3 + * @since 2.2 + */ +@SuppressWarnings("nls") +public interface XML +{ + String VERSION = "version"; + + String NAMESPACE = "xmlns"; + + String NAMESPACE_XSI = "xmlns:xsi"; + String XSI_NAMESPACE_URL = "http://www.w3.org/2001/XMLSchema-instance"; + + String XSI_SCHEMA_LOCATION = "xsi:schemaLocation"; +} |