锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产一区二区三区国产,国产99精品,国产乱码精品一区二区三区卡http://www.aygfsteel.com/baiyucheng/category/36062.htmlWait + Hope = Wisdomzh-cnTue, 25 Nov 2008 18:46:08 GMTTue, 25 Nov 2008 18:46:08 GMT60EMF鍩虹鐭ヨ瘑縐瘡http://www.aygfsteel.com/baiyucheng/archive/2008/11/25/242657.html鐧界帀鎴?/dc:creator>鐧界帀鎴?/author>Tue, 25 Nov 2008 14:26:00 GMThttp://www.aygfsteel.com/baiyucheng/archive/2008/11/25/242657.htmlhttp://www.aygfsteel.com/baiyucheng/comments/242657.htmlhttp://www.aygfsteel.com/baiyucheng/archive/2008/11/25/242657.html#Feedback0http://www.aygfsteel.com/baiyucheng/comments/commentRss/242657.htmlhttp://www.aygfsteel.com/baiyucheng/services/trackbacks/242657.html
  1. EMF core 闄や簡鐢熸垚model鍜?/span>model implementation澶栵紝鑷沖皯榪樼敓鎴愪袱涓帴鍙o細*Factory鍜?/span>*Package銆傚叾涓?/span>, Factory錛氱敓鎴愬疄渚嬬殑宸ュ巶錛?/span>Package錛氭彁渚涗竴浜涢潤鎬佺殑constants錛堜緥濡傦細琚敤鏉ョ敓鎴愭柟娉曠殑feature constants     錛夊拰涓浜涜闂ā鍨嬪厓鏁版嵁鐨勫叕鐢ㄦ柟娉曘?/span>

 

2. EMF鐢熸垚鐨勬柟娉曢兘甯︽湁“@generated”鏍囩銆?/span>EMF閲嶆柊鐢熸垚浠g爜鏃朵笉浼氳鐩栫敤鎴鋒坊鍔犵殑鏂規硶錛堜笉甯︽湁@generated錛夈?/span>

 

3. 鍏充簬URI錛?/span>Uniform Resource Identifier錛?/span>

鍦?/span>EMF 涓槸閫氳繃URI鏉ユ爣璇?/span>package鐨勶紝騫朵笖閫氳繃URI鏉ュ敮涓鐨勭‘瀹?/span>resources銆?/span>URI鍖呮嫭涓変釜閮ㄥ垎錛?/span>a scheme, a scheme-specific part鍜?/span>an optional fragment銆?/span>scheme涓昏鍐沖畾浜嗚闂?/span>

璧勬簮鐨勫崗璁紱姣斿錛?/span>Platform:/resource/……涓殑platform銆?/span>scheme-specific part鍖呭惈涓浜?/span>authority, device鍜屼竴浜?/span>segments錛屽file:/c:/dir1/dir2/myfile.xml錛?/span>file鏄崗璁紝娌℃湁authority錛?/span>c:鏄?/span>device,鍓╀笅鐨?/span>3涓槸segments銆?/span>URI fragment 鏍囪瘑浜?/span>resource鍐呴儴鐨勬煇涓叿浣撶殑鍐呭銆傚錛?/span>file:/c:/dir1/dir2/myfile.xml#loc涓殑#loc銆?/span> EMF閫氳繃甯︽湁fragment鐨?/span>URI鏉ヨ闂祫婧愪腑鐨?/span>EObjects銆?/span>

 

4. 鍏充簬URIConverter

URIConverter鐨勪綔鐢ㄦ槸normalize涓涓緭鍏?/span>URI錛屼嬌涔嬫垚涓轟竴涓疄闄呯殑閽堝鏌愪釜resource鐨?/span>URI銆傚畠鍙互鎶?/span>namespace URIs錛堟瘮濡傦細http:///com/example/epo2.ecore錛夋槧灝勫埌鐗╃悊鏂囦歡鐨?/span>URIs, 鎴栬呴噸瀹氬悜鏃х殑錛堟垨鍒悕錛夌殑URI鍙傝冨埌涓涓叿浣撶殑瀹為檯鐨?/span>location銆備竴涓?/span>URIConverter緇存姢涓涓?/span>URI鍒?/span>URI鐨勬槧灝勯泦鍚堛傛瘮濡傦紝鎶婁竴涓懡鍚嶇┖闂?/span>URI鏄犲皠鍒扮墿鐞嗘枃浠訛細

URIConverter converter = new URIConverterImpl();

URI uri1 = URI.createURI("http:///somemodel.ecore");

URI uri2 =URI.createURI("platform:/resource/project/somemodel.ecore");

converter.getURIMap().put(uri1, uri2);

鍦ㄥ涓嬮潰浠g爜錛?/span>

URI normalized = converter.normalize(uri1);

System.out.println(normalized);

鎵撳嵃鐨勭粨鏋滄槸錛?/span>platform:/resource/project/somemodel.ecore

URIConverter.normalize()鏂規硶鍙槸綆鍗曠殑閫氳繃鏄犲皠鐨?/span>map鎶?/span>key鏇挎崲鎴愪簡鐩稿簲鐨?/span>value銆?/span>

URIConverter鐨勬渶鍘熷鏄簲鐢ㄥ湪resource sets錛岀敤鏉ュ畾浣?/span>resources.

 

5. 鍏充簬Resource鍜?/span>ResourceSet

Resource 琛ㄧず涓涓寔涔呭寲鐨?/span>EOjbects鐨勫鍣紱ResourceSet琛ㄧず涓緇?/span>Resource鐨勯泦鍚堬紝闆嗗悎涓殑Resource鍚屾椂鍒涘緩鎴栧姞杞姐?/span>Resource涓瘮杈冮噸瑕佺殑灝辨槸save鍜?/span>load鏂規硶錛岃繕鏈夐氳繃URI fragments璁塊棶璧勬簮涓殑Object鐨勬満鍒訛紝濡傦細

Resource resource =…

Item item = (Item)resource.getEObject("http://@orders.0/@items.2");

Item item =…

String fragment = resource.getURIFragment(item);

涓婇潰浠g爜涓殑涓や釜鏂規硶錛?/span>getEObject閫氳繃甯︽湁fregment鐨?/span>URI鑾峰緱涓涓?/span>EObject錛屼笌涔嬬浉鍙嶇殑鏂規硶getURIFragment()閫氳繃EObject鑾峰緱鐩稿簲鐨?/span>fragment path銆?/span>

ResourceSet涓湁浜涢噸瑕佺殑鏂規硶錛?/span>

createResource()鍒涘緩涓涓┖鐨?/span>Resource錛?/span>

getResource()閫氳繃resource鐨?/span>URI鏉ュ垱寤?/span>Resource錛?/span>

getEObject()錛岄氳繃URI涓殑fregment鏉ヨ幏寰楀叿浣撶殑EObject瀵硅薄銆?/span>

 

6. 鍏充簬Resource.Factory

鐢ㄦ潵鍒涘緩Resource錛?/span>resource factory 瑕佹敞鍐屽埌Registry瀹炰緥涓備竴涓?/span>factory 鍙互閫氳繃澶氱鏂瑰紡鐨?/span>URIs鏉ユ敞鍐岋紝鍖呮嫭URI scheme鎴栬?/span>URI鐨?/span>extension銆傚湪鎻掍歡鏂瑰紡鐨勫簲鐢ㄤ腑錛岄氳繃鎵╁睍鐐圭殑鏂瑰紡鍦ㄦ彃浠跺姞杞界殑鏃跺欐敞鍐?/span>descriptor銆備笅闈㈡槸Resource鐨勬簮浠g爜

public interface Resource extends Notifier

{

interface Factory

{

Resource createResource(URI uri);

interface Descriptor

{

Factory createFactory();

}

interface Registry

{

Factory getFactory(URI uri);

Map getProtocolToFactoryMap();

String DEFAULT_EXTENSION = "*";

Map getExtensionToFactoryMap();

Registry INSTANCE = new ResourceFactoryRegistryImpl

();

}

}

}

涓嬮潰鏄?/span>Registry涓殑getFactory()鏂規硶鐨勭畻娉曪紙寮曠敤鍘熸枃錛夛細

1. Check for a factory in the protocolToFactoryMap, using

the scheme of the URI.

2. If nothing was found, check the extensionToFactoryMap

using the file extension of the URI.

3. If still nothing was found, check the

extensionToFactoryMap using the DEFAULT_EXTENSION

(that is, the wildcard character "*").

4. If no extension match was found, call the

delegatedGetFactory() method. This allows you to supply

your own factory registry, with its own lookup

criteria.

5. If a descriptor was found, instead of an actual

factory, call the createFactory() method on the

descriptor to create the factory.

6. Finally, return the factory if one was found, or null.

tip錛?/span>emf緙虹渷鐨勫簭鍒楀寲鏂瑰紡鏄?/span>XMI銆傚洜姝わ紝濡傛灉娌℃湁鎵懼埌鐩稿簲娉ㄥ唽鐨?/span>factory緙虹渷鐨勫氨浼氳繑鍥炰互*娉ㄥ唽鐨勭己鐪佺殑factory錛岃繖涓?/span>factory鏄拡瀵?/span>XMI鐨?/span>factory錛屽嵆XMIResourceFactoryImpl銆傚錛屽浜?/span>XMIResourceFactoryImpl鐨勬墿灞曠偣澹版槑:

<extension point = "org.eclipse.emf.ecore.extension_parser">

<parser type="*" class="org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl"/>

</extension>

褰撻潪鎻掍歡搴旂敤鐨勬椂鍊欙紝鍙互閫氳繃鎵嬪伐鐨勬柟寮忔潵娉ㄥ唽factory錛屽錛?/span>

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put

("*", new XMIResourceFactoryImpl());

 

7. Resource閫氳繃涓ょ鏂瑰紡瀹炵幇XML鍜?/span>XMI銆?/span>

1) XML

瀹炵幇Resource瀛樺偍鐨勯噸瑕佹柟娉曟槸save, 鍙湁鍦ㄦ柟娉?/span>eIsSet()榪斿洖true鏃訛紝鐩稿叧鐨勫睘鎬у拰寮曠敤鎵嶄細琚簭鍒楀寲鍒?/span>xml涓傚浜庡瓨鍌ㄧ殑xml鏂囦歡鐨勬牸寮忓彲浠ラ氳繃璁劇疆OPTION_XML_MAP灞炴ф潵瀹屾垚錛屽涓嬮潰鍘熸枃錛?/span>

There are several reasons why you might want to use OPTION_XML_MAP when saving a resource:

1. You want to save your data so that it conforms to a particular XML Schema.

2. You have changed your model, and you want the resource to produce XML documents that will work with the old version of the model.

3. You want to design your own XML format without changing your model.

2) XMI

XMI鍜?/span>XML鍩烘湰鐩稿悓錛?/span>XMIResourceImpl灝辨槸

XMLResourceImpl鐨勭畝鍗曠戶鎵匡紝鍙槸鍦ㄥ紩鐢?/span>objects鏃朵嬌鐢?/span>XMI IDs



]]>
主站蜘蛛池模板: 广元市| 白银市| 于田县| 彝良县| 前郭尔| 玉门市| 滕州市| 桂平市| 汤原县| 连州市| 汕头市| 澄江县| 泰安市| 台安县| 阜宁县| 灌云县| 东台市| 丰宁| 沂源县| 松原市| 行唐县| 乌鲁木齐市| 蓬溪县| 庆安县| 藁城市| 祥云县| 涡阳县| 宁蒗| 长泰县| 永昌县| 城市| 鹿邑县| 兰州市| 肇州县| 北海市| 永清县| 阜阳市| 崇文区| 台东市| 丹阳市| 大同市|